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:
@@ -42,10 +42,5 @@ namespace Content.Client.GameObjects.EntitySystems
|
||||
{
|
||||
FrameUpdate(frameTime);
|
||||
}
|
||||
|
||||
protected override void SetController(IPhysicsComponent physics)
|
||||
{
|
||||
physics.SetController<MoverController>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -567,7 +567,7 @@ namespace Content.Server.GameObjects
|
||||
}
|
||||
|
||||
// set velocity to zero
|
||||
physics.LinearVelocity = Vector2.Zero;
|
||||
physics.Stop();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,24 +134,6 @@ namespace Content.Server.GameObjects.Components
|
||||
return new ItemComponentState(EquippedPrefix);
|
||||
}
|
||||
|
||||
public void Fumble()
|
||||
{
|
||||
if (Owner.TryGetComponent<IPhysicsComponent>(out var physicsComponent))
|
||||
{
|
||||
physicsComponent.LinearVelocity += RandomOffset();
|
||||
}
|
||||
}
|
||||
|
||||
private Vector2 RandomOffset()
|
||||
{
|
||||
return new Vector2(RandomOffset(), RandomOffset());
|
||||
float RandomOffset()
|
||||
{
|
||||
var size = 15.0F;
|
||||
return (_robustRandom.NextFloat() * size) - size / 2;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnExplosion(ExplosionEventArgs eventArgs)
|
||||
{
|
||||
var sourceLocation = eventArgs.Source;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Content.Server.GameObjects.Components.Mobs;
|
||||
using Content.Shared.GameObjects.Components.Movement;
|
||||
using Content.Shared.Physics;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.GameObjects.Components.Container;
|
||||
using Robust.Shared.GameObjects;
|
||||
@@ -70,7 +71,8 @@ namespace Content.Server.GameObjects.Components.Movement
|
||||
collideComp.PhysicsShapes.Add(new PhysShapeGrid(grid));
|
||||
}
|
||||
|
||||
physComp.LinearVelocity = CalcNewVelocity(direction, enabled) * CurrentWalkSpeed;
|
||||
var controller = physComp.EnsureController<ShuttleController>();
|
||||
controller.Push(CalcNewVelocity(direction, enabled), CurrentWalkSpeed);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace Content.Server.GameObjects.Components
|
||||
void ICollideBehavior.CollideWith(IEntity entity)
|
||||
{
|
||||
if (!_shouldCollide) return;
|
||||
if (entity.TryGetComponent(out CollidableComponent collid))
|
||||
if (entity.TryGetComponent(out CollidableComponent collid))
|
||||
{
|
||||
if (!collid.Hard) // ignore non hard
|
||||
return;
|
||||
@@ -65,10 +65,13 @@ namespace Content.Server.GameObjects.Components
|
||||
{
|
||||
body.PhysicsShapes[0].CollisionMask &= (int) ~CollisionGroup.ThrownItem;
|
||||
|
||||
var physics = Owner.GetComponent<IPhysicsComponent>();
|
||||
physics.LinearVelocity = Vector2.Zero;
|
||||
physics.Status = BodyStatus.OnGround;
|
||||
if (body.TryGetController(out ThrownController controller))
|
||||
{
|
||||
controller.LinearVelocity = Vector2.Zero;
|
||||
}
|
||||
|
||||
body.Status = BodyStatus.OnGround;
|
||||
|
||||
Owner.RemoveComponent<ThrownItemComponent>();
|
||||
EntitySystem.Get<InteractionSystem>().LandInteraction(User, Owner, Owner.Transform.GridPosition);
|
||||
}
|
||||
@@ -82,11 +85,14 @@ namespace Content.Server.GameObjects.Components
|
||||
}
|
||||
}
|
||||
|
||||
public void StartThrow(Vector2 initialImpulse)
|
||||
public void StartThrow(Vector2 direction, float speed)
|
||||
{
|
||||
var comp = Owner.GetComponent<IPhysicsComponent>();
|
||||
comp.Status = BodyStatus.InAir;
|
||||
comp.Momentum = initialImpulse;
|
||||
|
||||
var controller = comp.EnsureController<ThrownController>();
|
||||
controller.Push(direction, speed);
|
||||
|
||||
StartStopTimer();
|
||||
}
|
||||
|
||||
@@ -110,5 +116,12 @@ namespace Content.Server.GameObjects.Components
|
||||
|
||||
StopThrow();
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
Owner.EnsureComponent<CollidableComponent>().EnsureController<ThrownController>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ using Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition;
|
||||
using Content.Shared.Audio;
|
||||
using Content.Shared.GameObjects.Components.Weapons.Ranged;
|
||||
using Content.Shared.Interfaces.GameObjects.Components;
|
||||
using Content.Shared.Physics;
|
||||
using Robust.Server.GameObjects.EntitySystems;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameObjects.Components;
|
||||
@@ -380,7 +381,12 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
|
||||
var projectileComponent = projectile.GetComponent<ProjectileComponent>();
|
||||
projectileComponent.IgnoreEntity(shooter);
|
||||
projectile.GetComponent<IPhysicsComponent>().LinearVelocity = projectileAngle.ToVec() * velocity;
|
||||
|
||||
projectile
|
||||
.GetComponent<IPhysicsComponent>()
|
||||
.EnsureController<BulletController>()
|
||||
.LinearVelocity = projectileAngle.ToVec() * velocity;
|
||||
|
||||
projectile.Transform.LocalRotation = projectileAngle.Theta;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,11 +78,6 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
}
|
||||
}
|
||||
|
||||
protected override void SetController(IPhysicsComponent physics)
|
||||
{
|
||||
physics.SetController<MoverController>();
|
||||
}
|
||||
|
||||
private static void PlayerAttached(PlayerAttachSystemMessage ev)
|
||||
{
|
||||
if (!ev.Entity.HasComponent<IMoverComponent>())
|
||||
@@ -98,9 +93,10 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
ev.Entity.RemoveComponent<PlayerInputMoverComponent>();
|
||||
}
|
||||
|
||||
if (ev.Entity.TryGetComponent(out IPhysicsComponent physics))
|
||||
if (ev.Entity.TryGetComponent(out IPhysicsComponent physics) &&
|
||||
physics.TryGetController(out MoverController controller))
|
||||
{
|
||||
(physics.Controller as MoverController)?.StopMoving();
|
||||
controller.StopMoving();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -75,18 +75,14 @@ namespace Content.Server.Throw
|
||||
throwSourceEnt.Transform.LocalRotation = angle.GetCardinalDir().ToAngle();
|
||||
}
|
||||
|
||||
if (!thrownEnt.TryGetComponent(out IPhysicsComponent physComp))
|
||||
physComp = thrownEnt.AddComponent<PhysicsComponent>();
|
||||
// scaling is handled elsewhere, this is just multiplying by 10 independent of timing as a fix until elsewhere values are updated
|
||||
var spd = throwForce * 10;
|
||||
|
||||
var timing = IoCManager.Resolve<IGameTiming>();
|
||||
projComp.StartThrow(angle.ToVec(), spd);
|
||||
|
||||
// scaling is handled elsewhere, this is just multiplying by 60 independent of timing as a fix until elsewhere values are updated
|
||||
var spd = throwForce * 60;
|
||||
|
||||
projComp.StartThrow(angle.ToVec() * spd);
|
||||
|
||||
if (throwSourceEnt != null && throwSourceEnt.TryGetComponent<IPhysicsComponent>(out var physics)
|
||||
&& physics.Controller is MoverController mover)
|
||||
if (throwSourceEnt != null &&
|
||||
throwSourceEnt.TryGetComponent<IPhysicsComponent>(out var physics) &&
|
||||
physics.TryGetController(out MoverController mover))
|
||||
{
|
||||
var physicsMgr = IoCManager.Resolve<IPhysicsManager>();
|
||||
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
17
Content.Shared/Physics/BulletController.cs
Normal file
17
Content.Shared/Physics/BulletController.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
17
Content.Shared/Physics/ShuttleController.cs
Normal file
17
Content.Shared/Physics/ShuttleController.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
17
Content.Shared/Physics/ThrownController.cs
Normal file
17
Content.Shared/Physics/ThrownController.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user