Pulling rework (#20906)
* Pulling rework Fixing up the FOUR systems managing pulling, all the shitcode, and also making it nicer ingame. * More pulling cleanup * stats * More cleanup * First draft * More pulling * weh * Fix puller * Pulling working * Fix merge * Dunked * Self-merge time
This commit is contained in:
@@ -20,6 +20,11 @@ public sealed class ThrowingSystem : EntitySystem
|
||||
{
|
||||
public const float ThrowAngularImpulse = 5f;
|
||||
|
||||
/// <summary>
|
||||
/// Speed cap on rotation in case of click-spam.
|
||||
/// </summary>
|
||||
public const float ThrowAngularCap = 3f * MathF.PI;
|
||||
|
||||
public const float PushbackDefault = 2f;
|
||||
|
||||
/// <summary>
|
||||
@@ -42,15 +47,17 @@ public sealed class ThrowingSystem : EntitySystem
|
||||
float strength = 1.0f,
|
||||
EntityUid? user = null,
|
||||
float pushbackRatio = PushbackDefault,
|
||||
bool recoil = true,
|
||||
bool animated = true,
|
||||
bool playSound = true)
|
||||
{
|
||||
var thrownPos = Transform(uid).MapPosition;
|
||||
var mapPos = coordinates.ToMap(EntityManager, _transform);
|
||||
var thrownPos = _transform.GetMapCoordinates(uid);
|
||||
var mapPos = _transform.ToMapCoordinates(coordinates);
|
||||
|
||||
if (mapPos.MapId != thrownPos.MapId)
|
||||
return;
|
||||
|
||||
TryThrow(uid, mapPos.Position - thrownPos.Position, strength, user, pushbackRatio, playSound);
|
||||
TryThrow(uid, mapPos.Position - thrownPos.Position, strength, user, pushbackRatio, recoil: recoil, animated: animated, playSound: playSound);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -65,6 +72,8 @@ public sealed class ThrowingSystem : EntitySystem
|
||||
float strength = 1.0f,
|
||||
EntityUid? user = null,
|
||||
float pushbackRatio = PushbackDefault,
|
||||
bool recoil = true,
|
||||
bool animated = true,
|
||||
bool playSound = true)
|
||||
{
|
||||
var physicsQuery = GetEntityQuery<PhysicsComponent>();
|
||||
@@ -72,7 +81,6 @@ public sealed class ThrowingSystem : EntitySystem
|
||||
return;
|
||||
|
||||
var projectileQuery = GetEntityQuery<ProjectileComponent>();
|
||||
var tagQuery = GetEntityQuery<TagComponent>();
|
||||
|
||||
TryThrow(
|
||||
uid,
|
||||
@@ -82,8 +90,7 @@ public sealed class ThrowingSystem : EntitySystem
|
||||
projectileQuery,
|
||||
strength,
|
||||
user,
|
||||
pushbackRatio,
|
||||
playSound);
|
||||
pushbackRatio, recoil: recoil, animated: animated, playSound: playSound);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -101,6 +108,8 @@ public sealed class ThrowingSystem : EntitySystem
|
||||
float strength = 1.0f,
|
||||
EntityUid? user = null,
|
||||
float pushbackRatio = PushbackDefault,
|
||||
bool recoil = true,
|
||||
bool animated = true,
|
||||
bool playSound = true)
|
||||
{
|
||||
if (strength <= 0 || direction == Vector2Helpers.Infinity || direction == Vector2Helpers.NaN || direction == Vector2.Zero)
|
||||
@@ -116,12 +125,17 @@ public sealed class ThrowingSystem : EntitySystem
|
||||
if (projectileQuery.TryGetComponent(uid, out var proj) && !proj.OnlyCollideWhenShot)
|
||||
return;
|
||||
|
||||
var comp = new ThrownItemComponent();
|
||||
comp.Thrower = user;
|
||||
var comp = new ThrownItemComponent
|
||||
{
|
||||
Thrower = user,
|
||||
Animate = animated,
|
||||
};
|
||||
|
||||
// Estimate time to arrival so we can apply OnGround status and slow it much faster.
|
||||
var time = direction.Length() / strength;
|
||||
comp.ThrownTime = _gameTiming.CurTime;
|
||||
// TODO: This is a bandaid, don't do this.
|
||||
// if you want to force landtime have the caller handle it or add a new method.
|
||||
// did we launch this with something stronger than our hands?
|
||||
if (TryComp<HandsComponent>(comp.Thrower, out var hands) && strength > hands.ThrowForceMultiplier)
|
||||
comp.LandTime = comp.ThrownTime + TimeSpan.FromSeconds(time);
|
||||
@@ -166,7 +180,8 @@ public sealed class ThrowingSystem : EntitySystem
|
||||
if (user == null)
|
||||
return;
|
||||
|
||||
_recoil.KickCamera(user.Value, -direction * 0.04f);
|
||||
if (recoil)
|
||||
_recoil.KickCamera(user.Value, -direction * 0.04f);
|
||||
|
||||
// Give thrower an impulse in the other direction
|
||||
if (pushbackRatio != 0.0f &&
|
||||
|
||||
@@ -8,6 +8,12 @@ namespace Content.Shared.Throwing
|
||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState(true)]
|
||||
public sealed partial class ThrownItemComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// Should the in-air throwing animation play.
|
||||
/// </summary>
|
||||
[DataField, AutoNetworkedField]
|
||||
public bool Animate = true;
|
||||
|
||||
/// <summary>
|
||||
/// The entity that threw this entity.
|
||||
/// </summary>
|
||||
|
||||
@@ -3,8 +3,7 @@ using Content.Shared.Administration.Logs;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.Gravity;
|
||||
using Content.Shared.Physics;
|
||||
using Content.Shared.Physics.Pull;
|
||||
using Robust.Shared.GameStates;
|
||||
using Content.Shared.Movement.Pulling.Events;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Components;
|
||||
using Robust.Shared.Physics.Events;
|
||||
@@ -94,8 +93,8 @@ namespace Content.Shared.Throwing
|
||||
private void HandlePullStarted(PullStartedMessage message)
|
||||
{
|
||||
// TODO: this isn't directed so things have to be done the bad way
|
||||
if (EntityManager.TryGetComponent(message.Pulled.Owner, out ThrownItemComponent? thrownItemComponent))
|
||||
StopThrow(message.Pulled.Owner, thrownItemComponent);
|
||||
if (EntityManager.TryGetComponent(message.PulledUid, out ThrownItemComponent? thrownItemComponent))
|
||||
StopThrow(message.PulledUid, thrownItemComponent);
|
||||
}
|
||||
|
||||
public void StopThrow(EntityUid uid, ThrownItemComponent thrownItemComponent)
|
||||
|
||||
Reference in New Issue
Block a user