Refactor to use the new multiple controller system (#1462)

* Transition code to new controller system

* Fix shuttles not moving

* Fix throwing

* Fix guns

* Change hands to use physics.Stop() and remove item fumble method
This commit is contained in:
DrSmugleaf
2020-07-23 18:33:37 +02:00
committed by GitHub
parent 3296079400
commit 64672fdc31
13 changed files with 114 additions and 101 deletions

View File

@@ -57,11 +57,7 @@ namespace Content.Shared.GameObjects.EntitySystems
protected void UpdateKinematics(ITransformComponent transform, IMoverComponent mover, IPhysicsComponent physics,
ICollidableComponent? collider = null)
{
if (physics.Controller == null)
{
// Set up controller
SetController(physics);
}
physics.EnsureController<MoverController>();
var weightless = !transform.Owner.HasComponent<MovementIgnoreGravityComponent>() &&
_physicsManager.IsWeightless(transform.GridPosition);
@@ -82,7 +78,10 @@ namespace Content.Shared.GameObjects.EntitySystems
var combined = walkDir + sprintDir;
if (combined.LengthSquared < 0.001 || !ActionBlockerSystem.CanMove(mover.Owner) && !weightless)
{
(physics.Controller as MoverController)?.StopMoving();
if (physics.TryGetController(out MoverController controller))
{
controller.StopMoving();
}
}
else
{
@@ -90,7 +89,11 @@ namespace Content.Shared.GameObjects.EntitySystems
if (weightless)
{
(physics.Controller as MoverController)?.Push(combined, mover.CurrentPushSpeed);
if (physics.TryGetController(out MoverController controller))
{
controller.Push(combined, mover.CurrentPushSpeed);
}
transform.LocalRotation = walkDir.GetDir().ToAngle();
return;
}
@@ -98,7 +101,11 @@ namespace Content.Shared.GameObjects.EntitySystems
var total = walkDir * mover.CurrentWalkSpeed + sprintDir * mover.CurrentSprintSpeed;
//Console.WriteLine($"{walkDir} ({mover.CurrentWalkSpeed}) + {sprintDir} ({mover.CurrentSprintSpeed}): {total}");
(physics.Controller as MoverController)?.Move(total, 1);
{if (physics.TryGetController(out MoverController controller))
{
controller.Move(total, 1);
}}
transform.LocalRotation = total.GetDir().ToAngle();
HandleFootsteps(mover);
@@ -110,8 +117,6 @@ namespace Content.Shared.GameObjects.EntitySystems
}
protected abstract void SetController(IPhysicsComponent physics);
private bool IsAroundCollider(ITransformComponent transform, IMoverComponent mover,
ICollidableComponent collider)
{

View File

@@ -0,0 +1,17 @@
#nullable enable
using Robust.Shared.GameObjects.Components;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
namespace Content.Shared.Physics
{
public class BulletController : VirtualController
{
public override ICollidableComponent? ControlledComponent { protected get; set; }
public void Push(Vector2 velocityDirection, float speed)
{
LinearVelocity = velocityDirection * speed;
}
}
}

View File

@@ -10,60 +10,27 @@ namespace Content.Shared.Physics
{
public class MoverController : VirtualController
{
private Vector2 _velocity;
private ICollidableComponent? _component;
public Vector2 Velocity
{
get => _velocity;
set => _velocity = value;
}
public override ICollidableComponent? ControlledComponent
{
set => _component = value;
}
public MoverController()
{
_velocity = Vector2.Zero;
}
public override ICollidableComponent? ControlledComponent { protected get; set; }
public void Move(Vector2 velocityDirection, float speed)
{
if (_component?.Owner.HasComponent<MovementIgnoreGravityComponent>() == false
&& IoCManager.Resolve<IPhysicsManager>().IsWeightless(_component.Owner.Transform.GridPosition)) return;
if (ControlledComponent?.Owner.HasComponent<MovementIgnoreGravityComponent>() == false
&& IoCManager.Resolve<IPhysicsManager>().IsWeightless(ControlledComponent.Owner.Transform.GridPosition))
{
return;
}
Push(velocityDirection, speed);
}
public void Push(Vector2 velocityDirection, float speed)
{
Velocity = velocityDirection * speed;
LinearVelocity = velocityDirection * speed;
}
public void StopMoving()
{
Velocity = Vector2.Zero;
}
public override void UpdateBeforeProcessing()
{
base.UpdateBeforeProcessing();
if (_component == null)
{
return;
}
if (Velocity == Vector2.Zero)
{
// Try to stop movement
_component.LinearVelocity = Vector2.Zero;
}
else
{
_component.LinearVelocity = Velocity;
}
LinearVelocity = Vector2.Zero;
}
}
}

View File

@@ -0,0 +1,17 @@
#nullable enable
using Robust.Shared.GameObjects.Components;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
namespace Content.Shared.Physics
{
public class ShuttleController : VirtualController
{
public override ICollidableComponent? ControlledComponent { protected get; set; }
public void Push(Vector2 velocityDirection, float speed)
{
LinearVelocity = velocityDirection * speed;
}
}
}

View File

@@ -0,0 +1,17 @@
#nullable enable
using Robust.Shared.GameObjects.Components;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
namespace Content.Shared.Physics
{
public class ThrownController : VirtualController
{
public override ICollidableComponent? ControlledComponent { protected get; set; }
public void Push(Vector2 velocityDirection, float speed)
{
LinearVelocity = velocityDirection * speed;
}
}
}