Converted everything to use collision and physics component interfaces.

This commit is contained in:
Acruid
2020-07-19 00:33:02 -07:00
parent ea94f4a182
commit c9374992a6
29 changed files with 75 additions and 75 deletions

View File

@@ -19,7 +19,7 @@ namespace Content.Server.GameObjects.Components
public bool InteractUsing(InteractUsingEventArgs eventArgs)
{
if (!Owner.TryGetComponent(out PhysicsComponent physics)
if (!Owner.TryGetComponent(out IPhysicsComponent physics)
|| !eventArgs.Using.TryGetComponent(out ToolComponent tool))
return false;

View File

@@ -36,7 +36,7 @@ namespace Content.Server.GameObjects
protected const float AutoCloseDelay = 5;
protected float CloseSpeed = AutoCloseDelay;
private CollidableComponent collidableComponent;
private ICollidableComponent _collidableComponent;
private AppearanceComponent _appearance;
private CancellationTokenSource _cancellationTokenSource;
@@ -64,7 +64,7 @@ namespace Content.Server.GameObjects
{
base.Initialize();
collidableComponent = Owner.GetComponent<CollidableComponent>();
_collidableComponent = Owner.GetComponent<ICollidableComponent>();
_appearance = Owner.GetComponent<AppearanceComponent>();
_cancellationTokenSource = new CancellationTokenSource();
}
@@ -72,7 +72,7 @@ namespace Content.Server.GameObjects
public override void OnRemove()
{
_cancellationTokenSource.Cancel();
collidableComponent = null;
_collidableComponent = null;
_appearance = null;
base.OnRemove();
@@ -164,7 +164,7 @@ namespace Content.Server.GameObjects
Timer.Spawn(OpenTimeOne, async () =>
{
collidableComponent.Hard = false;
_collidableComponent.Hard = false;
await Timer.Delay(OpenTimeTwo, _cancellationTokenSource.Token);
@@ -203,7 +203,7 @@ namespace Content.Server.GameObjects
private void CheckCrush()
{
// Check if collides with something
var collidesWith = collidableComponent.GetCollidingEntities(Vector2.Zero, false);
var collidesWith = _collidableComponent.GetCollidingEntities(Vector2.Zero, false);
if (collidesWith.Count() != 0)
{
// Crush
@@ -236,7 +236,7 @@ namespace Content.Server.GameObjects
public bool Close()
{
bool shouldCheckCrush = false;
if (collidableComponent.IsColliding(Vector2.Zero, false))
if (_collidableComponent.IsColliding(Vector2.Zero, false))
{
if (Safety)
return false;
@@ -260,7 +260,7 @@ namespace Content.Server.GameObjects
CheckCrush();
}
collidableComponent.Hard = true;
_collidableComponent.Hard = true;
await Timer.Delay(CloseTimeTwo, _cancellationTokenSource.Token);

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
@@ -393,7 +393,7 @@ namespace Content.Server.GameObjects.Components.Fluids
foreach (var entity in _snapGrid.GetInDir(direction))
{
if (entity.TryGetComponent(out CollidableComponent collidable) &&
if (entity.TryGetComponent(out ICollidableComponent collidable) &&
(collidable.CollisionLayer & (int) CollisionGroup.Impassable) != 0)
{
puddle = default;

View File

@@ -568,7 +568,7 @@ namespace Content.Server.GameObjects
Dirty();
if (!message.Entity.TryGetComponent(out PhysicsComponent physics))
if (!message.Entity.TryGetComponent(out IPhysicsComponent physics))
{
return;
}

View File

@@ -136,7 +136,7 @@ namespace Content.Server.GameObjects.Components
public void Fumble()
{
if (Owner.TryGetComponent<PhysicsComponent>(out var physicsComponent))
if (Owner.TryGetComponent<IPhysicsComponent>(out var physicsComponent))
{
physicsComponent.LinearVelocity += RandomOffset();
}

View File

@@ -187,7 +187,7 @@ namespace Content.Server.GameObjects
StandingStateHelper.Down(entity);
if (entity.TryGetComponent(out CollidableComponent collidable))
if (entity.TryGetComponent(out ICollidableComponent collidable))
{
collidable.CanCollide = false;
}
@@ -197,7 +197,7 @@ namespace Content.Server.GameObjects
{
StandingStateHelper.Standing(entity);
if (entity.TryGetComponent(out CollidableComponent collidable))
if (entity.TryGetComponent(out ICollidableComponent collidable))
{
collidable.CanCollide = true;
}

View File

@@ -43,7 +43,7 @@ namespace Content.Server.GameObjects.Components.Movement
base.Initialize();
// This component requires a physics component.
if (!Owner.HasComponent<PhysicsComponent>())
if (!Owner.HasComponent<IPhysicsComponent>())
Owner.AddComponent<PhysicsComponent>();
}

View File

@@ -63,7 +63,7 @@ namespace Content.Server.GameObjects.Components.Movement
{
// This will blow up an entity it's attached to
base.OnAdd();
if (Owner.TryGetComponent<CollidableComponent>(out var collide))
if (Owner.TryGetComponent<ICollidableComponent>(out var collide))
{
//collide.IsHardCollidable = false;
}

View File

@@ -114,7 +114,7 @@ namespace Content.Server.GameObjects.Components.Movement
{
// Added this component to avoid stacking portals and causing shenanigans
// TODO: Doesn't do a great job of stopping stacking portals for directed
if (entity.HasComponent<CollidableComponent>() || entity.HasComponent<ServerTeleporterComponent>())
if (entity.HasComponent<ICollidableComponent>() || entity.HasComponent<ServerTeleporterComponent>())
{
return;
}
@@ -159,7 +159,7 @@ namespace Content.Server.GameObjects.Components.Movement
// TODO: Check the user's spot? Upside is no stacking TPs but downside is they can't unstuck themselves from walls.
foreach (var entity in _serverEntityManager.GetEntitiesIntersecting(user.Transform.MapID, target))
{
if (entity.HasComponent<CollidableComponent>() || entity.HasComponent<ServerPortalComponent>())
if (entity.HasComponent<ICollidableComponent>() || entity.HasComponent<ServerPortalComponent>())
{
return false;
}

View File

@@ -55,7 +55,7 @@ namespace Content.Server.GameObjects.Components.Movement
if (_mapManager.TryGetGrid(gridId, out var grid) && _entityManager.TryGetEntity(grid.GridEntityId, out var gridEntity))
{
//TODO: Switch to shuttle component
if (!gridEntity.TryGetComponent(out PhysicsComponent physComp))
if (!gridEntity.TryGetComponent(out IPhysicsComponent physComp))
{
physComp = gridEntity.AddComponent<PhysicsComponent>();
physComp.Mass = 1;

View File

@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Timers;
using Content.Server.GameObjects.Components.Mobs;
using Content.Server.Throw;
@@ -79,7 +79,7 @@ namespace Content.Server.GameObjects.Components.Movement
|| _slipped.Contains(collidedWith.Uid)
|| !collidedWith.TryGetComponent(out StunnableComponent stun)
|| !collidedWith.TryGetComponent(out ICollidableComponent otherBody)
|| !collidedWith.TryGetComponent(out PhysicsComponent otherPhysics)
|| !collidedWith.TryGetComponent(out IPhysicsComponent otherPhysics)
|| !Owner.TryGetComponent(out ICollidableComponent body))
return;

View File

@@ -38,7 +38,7 @@ namespace Content.Server.GameObjects.Components.NodeContainer.Nodes
/// </summary>
private bool Connectable => !_deleting && Anchored;
private bool Anchored => !Owner.TryGetComponent<PhysicsComponent>(out var physics) || physics.Anchored;
private bool Anchored => !Owner.TryGetComponent<IPhysicsComponent>(out var physics) || physics.Anchored;
/// <summary>
/// Prevents a node from being used by other nodes while midway through removal.
@@ -60,7 +60,7 @@ namespace Content.Server.GameObjects.Components.NodeContainer.Nodes
{
TryAssignGroupIfNeeded();
CombineGroupWithReachable();
if (Owner.TryGetComponent<PhysicsComponent>(out var physics))
if (Owner.TryGetComponent<IPhysicsComponent>(out var physics))
{
AnchorUpdate();
physics.AnchoredChanged += AnchorUpdate;
@@ -70,9 +70,9 @@ namespace Content.Server.GameObjects.Components.NodeContainer.Nodes
public void OnContainerRemove()
{
_deleting = true;
if (Owner.TryGetComponent<PhysicsComponent>(out var physics))
if (Owner.TryGetComponent<IPhysicsComponent>(out var physics))
{
physics.AnchoredChanged -= AnchorUpdate;
((IPhysicsComponent) physics).AnchoredChanged -= AnchorUpdate;
}
NodeGroup.RemoveNode(this);
}

View File

@@ -45,7 +45,7 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents
/// </summary>
public bool Connectable => Anchored;
private bool Anchored => !Owner.TryGetComponent<PhysicsComponent>(out var physics) || physics.Anchored;
private bool Anchored => !Owner.TryGetComponent<IPhysicsComponent>(out var physics) || physics.Anchored;
[ViewVariables]
public bool NeedsProvider { get; private set; } = true;
@@ -86,18 +86,18 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents
{
TryFindAndSetProvider();
}
if (Owner.TryGetComponent<PhysicsComponent>(out var physics))
if (Owner.TryGetComponent<IPhysicsComponent>(out var physics))
{
AnchorUpdate();
physics.AnchoredChanged += AnchorUpdate;
((IPhysicsComponent) physics).AnchoredChanged += AnchorUpdate;
}
}
public override void OnRemove()
{
if (Owner.TryGetComponent<PhysicsComponent>(out var physics))
if (Owner.TryGetComponent<IPhysicsComponent>(out var physics))
{
physics.AnchoredChanged -= AnchorUpdate;
((IPhysicsComponent) physics).AnchoredChanged -= AnchorUpdate;
}
_provider.RemoveReceiver(this);
base.OnRemove();

View File

@@ -91,7 +91,7 @@ namespace Content.Server.GameObjects.Components.Projectiles
}
if (!entity.Deleted && entity.TryGetComponent(out CameraRecoilComponent recoilComponent)
&& Owner.TryGetComponent(out PhysicsComponent physicsComponent))
&& Owner.TryGetComponent(out IPhysicsComponent physicsComponent))
{
var direction = physicsComponent.LinearVelocity.Normalized;
recoilComponent.Kick(direction);

View File

@@ -40,7 +40,7 @@ namespace Content.Server.GameObjects.Components
// after impacting the first object.
// For realism this should actually be changed when the velocity of the object is less than a threshold.
// This would allow ricochets off walls, and weird gravity effects from slowing the object.
if (Owner.TryGetComponent(out CollidableComponent body) && body.PhysicsShapes.Count >= 1)
if (Owner.TryGetComponent(out ICollidableComponent body) && body.PhysicsShapes.Count >= 1)
{
_shouldCollide = false;
}
@@ -53,11 +53,11 @@ namespace Content.Server.GameObjects.Components
return;
}
if (Owner.TryGetComponent(out CollidableComponent body) && body.PhysicsShapes.Count >= 1)
if (Owner.TryGetComponent(out ICollidableComponent body) && body.PhysicsShapes.Count >= 1)
{
body.PhysicsShapes[0].CollisionMask &= (int) ~CollisionGroup.ThrownItem;
var physics = Owner.GetComponent<PhysicsComponent>();
var physics = Owner.GetComponent<IPhysicsComponent>();
physics.LinearVelocity = Vector2.Zero;
physics.Status = BodyStatus.OnGround;
body.Status = BodyStatus.OnGround;
@@ -76,7 +76,7 @@ namespace Content.Server.GameObjects.Components
public void StartThrow(Vector2 initialImpulse)
{
var comp = Owner.GetComponent<PhysicsComponent>();
var comp = Owner.GetComponent<IPhysicsComponent>();
comp.Status = BodyStatus.InAir;
comp.Momentum = initialImpulse;
StartStopTimer();

View File

@@ -21,7 +21,7 @@ namespace Content.Server.GameObjects.Components
private void TryRotate(IEntity user, Angle angle)
{
if (Owner.TryGetComponent(out PhysicsComponent physics))
if (Owner.TryGetComponent(out IPhysicsComponent physics))
{
if (physics.Anchored)
{

View File

@@ -347,13 +347,13 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
projectileAngle = angle;
}
var physicsComponent = projectile.GetComponent<PhysicsComponent>();
var physicsComponent = projectile.GetComponent<IPhysicsComponent>();
physicsComponent.Status = BodyStatus.InAir;
projectile.Transform.GridPosition = Owner.Transform.GridPosition;
var projectileComponent = projectile.GetComponent<ProjectileComponent>();
projectileComponent.IgnoreEntity(shooter);
projectile.GetComponent<PhysicsComponent>().LinearVelocity = projectileAngle.ToVec() * velocity;
projectile.GetComponent<IPhysicsComponent>().LinearVelocity = projectileAngle.ToVec() * velocity;
projectile.Transform.LocalRotation = projectileAngle.Theta;
}
}