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

@@ -567,7 +567,7 @@ namespace Content.Server.GameObjects
}
// set velocity to zero
physics.LinearVelocity = Vector2.Zero;
physics.Stop();
return;
}
}

View File

@@ -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;

View File

@@ -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);
}
}

View File

@@ -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>();
}
}
}

View File

@@ -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;
}
}