@@ -9,7 +9,6 @@ using Robust.Shared.Localization;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Broadphase;
|
||||
|
||||
namespace Content.Shared.GameObjects.EntitySystems
|
||||
{
|
||||
@@ -19,6 +18,8 @@ namespace Content.Shared.GameObjects.EntitySystems
|
||||
[UsedImplicitly]
|
||||
public class SharedInteractionSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IPhysicsManager _physicsManager = default!;
|
||||
|
||||
public const float InteractionRange = 2;
|
||||
public const float InteractionRangeSquared = InteractionRange * InteractionRange;
|
||||
|
||||
@@ -48,7 +49,7 @@ namespace Content.Shared.GameObjects.EntitySystems
|
||||
|
||||
predicate ??= _ => false;
|
||||
var ray = new CollisionRay(origin.Position, dir.Normalized, collisionMask);
|
||||
var rayResults = Get<SharedBroadPhaseSystem>().IntersectRayWithPredicate(origin.MapId, ray, dir.Length, predicate.Invoke, false).ToList();
|
||||
var rayResults = _physicsManager.IntersectRayWithPredicate(origin.MapId, ray, dir.Length, predicate.Invoke, false).ToList();
|
||||
|
||||
if (rayResults.Count == 0) return dir.Length;
|
||||
return (rayResults[0].HitPos - origin.Position).Length;
|
||||
@@ -124,7 +125,7 @@ namespace Content.Shared.GameObjects.EntitySystems
|
||||
predicate ??= _ => false;
|
||||
|
||||
var ray = new CollisionRay(origin.Position, dir.Normalized, (int) collisionMask);
|
||||
var rayResults = Get<SharedBroadPhaseSystem>().IntersectRayWithPredicate(origin.MapId, ray, dir.Length, predicate.Invoke, false).ToList();
|
||||
var rayResults = _physicsManager.IntersectRayWithPredicate(origin.MapId, ray, dir.Length, predicate.Invoke, false).ToList();
|
||||
|
||||
if (rayResults.Count == 0) return true;
|
||||
|
||||
@@ -132,12 +133,12 @@ namespace Content.Shared.GameObjects.EntitySystems
|
||||
|
||||
foreach (var result in rayResults)
|
||||
{
|
||||
if (!result.HitEntity.TryGetComponent(out IPhysBody p))
|
||||
if (!result.HitEntity.TryGetComponent(out IPhysicsComponent p))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var bBox = p.GetWorldAABB();
|
||||
var bBox = p.WorldAABB;
|
||||
|
||||
if (bBox.Contains(origin.Position) || bBox.Contains(other.Position))
|
||||
{
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
#nullable enable
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Content.Shared.GameObjects.Components.Mobs.State;
|
||||
using Content.Shared.GameObjects.Components.Items;
|
||||
using Content.Shared.GameObjects.Components.Movement;
|
||||
using Content.Shared.GameObjects.EntitySystems.ActionBlocker;
|
||||
using Content.Shared.Physics;
|
||||
using Content.Shared.Physics.Pull;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Input;
|
||||
using Robust.Shared.Input.Binding;
|
||||
@@ -16,11 +15,11 @@ using Robust.Shared.Players;
|
||||
|
||||
namespace Content.Shared.GameObjects.EntitySystems
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles converting inputs into movement.
|
||||
/// </summary>
|
||||
public sealed class SharedMoverSystem : EntitySystem
|
||||
public abstract class SharedMoverSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
[Dependency] protected readonly IPhysicsManager PhysicsManager = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
@@ -46,9 +45,109 @@ namespace Content.Shared.GameObjects.EntitySystems
|
||||
base.Shutdown();
|
||||
}
|
||||
|
||||
//TODO: reorganize this to make more logical sense
|
||||
protected void UpdateKinematics(ITransformComponent transform, IMoverComponent mover, IPhysicsComponent physics)
|
||||
{
|
||||
physics.EnsureController<MoverController>();
|
||||
|
||||
var weightless = transform.Owner.IsWeightless();
|
||||
|
||||
if (weightless)
|
||||
{
|
||||
// No gravity: is our entity touching anything?
|
||||
var touching = IsAroundCollider(transform, mover, physics);
|
||||
|
||||
if (!touching)
|
||||
{
|
||||
transform.LocalRotation = physics.LinearVelocity.GetDir().ToAngle();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: movement check.
|
||||
var (walkDir, sprintDir) = mover.VelocityDir;
|
||||
var combined = walkDir + sprintDir;
|
||||
if (combined.LengthSquared < 0.001 || !ActionBlockerSystem.CanMove(mover.Owner) && !weightless)
|
||||
{
|
||||
if (physics.TryGetController(out MoverController controller))
|
||||
{
|
||||
controller.StopMoving();
|
||||
}
|
||||
}
|
||||
else if (ActionBlockerSystem.CanMove(mover.Owner))
|
||||
{
|
||||
if (weightless)
|
||||
{
|
||||
if (physics.TryGetController(out MoverController controller))
|
||||
{
|
||||
controller.Push(combined, mover.CurrentPushSpeed);
|
||||
}
|
||||
|
||||
transform.LocalRotation = physics.LinearVelocity.GetDir().ToAngle();
|
||||
return;
|
||||
}
|
||||
|
||||
var total = walkDir * mover.CurrentWalkSpeed + sprintDir * mover.CurrentSprintSpeed;
|
||||
|
||||
{
|
||||
if (physics.TryGetController(out MoverController controller))
|
||||
{
|
||||
controller.Move(total, 1);
|
||||
}
|
||||
}
|
||||
|
||||
transform.LocalRotation = total.GetDir().ToAngle();
|
||||
|
||||
HandleFootsteps(mover);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void HandleFootsteps(IMoverComponent mover)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private bool IsAroundCollider(ITransformComponent transform, IMoverComponent mover,
|
||||
IPhysicsComponent collider)
|
||||
{
|
||||
foreach (var entity in _entityManager.GetEntitiesInRange(transform.Owner, mover.GrabRange, true))
|
||||
{
|
||||
if (entity == transform.Owner)
|
||||
{
|
||||
continue; // Don't try to push off of yourself!
|
||||
}
|
||||
|
||||
if (!entity.TryGetComponent<IPhysicsComponent>(out var otherCollider) ||
|
||||
!otherCollider.CanCollide ||
|
||||
(collider.CollisionMask & otherCollider.CollisionLayer) == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Don't count pulled entities
|
||||
if (otherCollider.HasController<PullController>())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// TODO: Item check.
|
||||
var touching = ((collider.CollisionMask & otherCollider.CollisionLayer) != 0x0
|
||||
|| (otherCollider.CollisionMask & collider.CollisionLayer) != 0x0) // Ensure collision
|
||||
&& !entity.HasComponent<IItemComponent>(); // This can't be an item
|
||||
|
||||
if (touching)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private static void HandleDirChange(ICommonSession? session, Direction dir, ushort subTick, bool state)
|
||||
{
|
||||
if (!TryGetAttachedComponent<SharedPlayerInputMoverComponent>(session, out var moverComp))
|
||||
if (!TryGetAttachedComponent<IMoverComponent>(session, out var moverComp))
|
||||
return;
|
||||
|
||||
var owner = session?.AttachedEntity;
|
||||
@@ -59,15 +158,6 @@ namespace Content.Shared.GameObjects.EntitySystems
|
||||
{
|
||||
comp.MoveInputPressed(session);
|
||||
}
|
||||
|
||||
// For stuff like "Moving out of locker" or the likes
|
||||
if (owner.IsInContainer() &&
|
||||
(!owner.TryGetComponent(out IMobStateComponent? mobState) ||
|
||||
mobState.IsAlive()))
|
||||
{
|
||||
var relayEntityMoveMessage = new RelayMovementEntityMessage(owner);
|
||||
owner.Transform.Parent!.Owner.SendMessage(owner.Transform, relayEntityMoveMessage);
|
||||
}
|
||||
}
|
||||
|
||||
moverComp.SetVelocityDirection(dir, subTick, state);
|
||||
|
||||
@@ -8,7 +8,6 @@ using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Input.Binding;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Players;
|
||||
|
||||
namespace Content.Shared.GameObjects.EntitySystems
|
||||
@@ -59,7 +58,7 @@ namespace Content.Shared.GameObjects.EntitySystems
|
||||
return;
|
||||
}
|
||||
|
||||
if (!pulled.TryGetComponent(out IPhysBody? physics))
|
||||
if (!pulled.TryGetComponent(out IPhysicsComponent? physics))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user