From 0bcc91ae985d0b895b4050f67e983715dc28466d Mon Sep 17 00:00:00 2001 From: Vonsant Date: Thu, 20 Jun 2024 12:12:27 +0300 Subject: [PATCH] =?UTF-8?q?=D0=93=D1=80=D0=B0=D0=BF=D0=BF=D0=BB=D0=B8?= =?UTF-8?q?=D0=BD=D0=B3=D0=A5=D1=83=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Weapons/Misc/GrapplingGunSystem.cs | 7 +---- .../Weapons/Misc/SharedGrapplingGunSystem.cs | 29 ++++++++++++------- .../Components/GrapplingGunComponent.cs | 2 +- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/Content.Client/Weapons/Misc/GrapplingGunSystem.cs b/Content.Client/Weapons/Misc/GrapplingGunSystem.cs index df20042b4be..f79e6daf90b 100644 --- a/Content.Client/Weapons/Misc/GrapplingGunSystem.cs +++ b/Content.Client/Weapons/Misc/GrapplingGunSystem.cs @@ -21,8 +21,6 @@ public override void Update(float frameTime) { base.Update(frameTime); - // Oh boy another input handler. - // If someone thinks of a better way to unify this please tell me. if (!Timing.IsFirstTimePredicted) return; @@ -39,9 +37,6 @@ public override void Update(float frameTime) return; } - if (distance.MaxLength <= distance.MinLength) - return; - var reelKey = _input.CmdStates.GetState(EngineKeyFunctions.UseSecondary) == BoundKeyState.Down; if (!TryComp(local, out var combatMode) || @@ -55,4 +50,4 @@ public override void Update(float frameTime) RaisePredictiveEvent(new RequestGrapplingReelMessage(reelKey)); } -} +} \ No newline at end of file diff --git a/Content.Shared/Weapons/Misc/SharedGrapplingGunSystem.cs b/Content.Shared/Weapons/Misc/SharedGrapplingGunSystem.cs index 41e1895da2c..2c88fd5a346 100644 --- a/Content.Shared/Weapons/Misc/SharedGrapplingGunSystem.cs +++ b/Content.Shared/Weapons/Misc/SharedGrapplingGunSystem.cs @@ -30,8 +30,9 @@ public abstract class SharedGrapplingGunSystem : EntitySystem [Dependency] private readonly SharedPhysicsSystem _physics = default!; public const string GrapplingJoint = "grappling"; - public const float ReelRate = 2.5f; + public const float MaxGrappleDistance = 10.0f; // Maximum distance for the grappling hook + public const float ExtendRate = 2.5f; // Rate for extending the grapple public override void Initialize() { @@ -59,8 +60,6 @@ private void OnGrapplingShot(EntityUid uid, GrapplingGunComponent component, ref if (!HasComp(shotUid)) continue; - //todo: this doesn't actually support multigrapple - // At least show the visuals. component.Projectile = shotUid.Value; Dirty(uid, component); var visuals = EnsureComp(shotUid.Value); @@ -132,7 +131,7 @@ private void OnGunActivate(EntityUid uid, GrapplingGunComponent component, Activ component.Projectile = null; SetReeling(uid, component, false, args.User); - _gun.ChangeBasicEntityAmmoCount(uid, 1); + _gun.ChangeBasicEntityAmmoCount(uid, 1); args.Handled = true; } @@ -171,7 +170,6 @@ public override void Update(float frameTime) { if (Timing.IsFirstTimePredicted) { - // Just in case. grappling.Stream = _audio.Stop(grappling.Stream); } @@ -186,8 +184,19 @@ public override void Update(float frameTime) continue; } - // TODO: This should be on engine. - distance.MaxLength = MathF.Max(distance.MinLength, distance.MaxLength - ReelRate * frameTime); + var localTransform = Transform(uid); // Use the transform of the entity holding the grappling gun + var hookTransform = Transform(joint.BodyBUid); + var distanceBetween = (localTransform.Coordinates.Position - hookTransform.Coordinates.Position).Length(); + + if (grappling.Reeling) + { + distance.MaxLength = MathF.Max(distance.MinLength, distance.MaxLength - ReelRate * frameTime); + } + else + { + distance.MaxLength = MathF.Min(MaxGrappleDistance, distance.MaxLength + ExtendRate * frameTime); + } + distance.Length = MathF.Min(distance.MaxLength, distance.Length); _physics.WakeBody(joint.BodyAUid); @@ -214,11 +223,9 @@ private void OnGrappleCollide(EntityUid uid, GrapplingProjectileComponent compon var jointComp = EnsureComp(uid); var joint = _joints.CreateDistanceJoint(uid, args.Weapon, anchorA: new Vector2(0f, 0.5f), id: GrapplingJoint); - joint.MaxLength = joint.Length + 0.2f; + joint.MaxLength = MaxGrappleDistance; // Set the initial maximum distance to the defined maximum joint.Stiffness = 1f; joint.MinLength = 0.35f; - // Setting velocity directly for mob movement fucks this so need to make them aware of it. - // joint.Breakpoint = 4000f; Dirty(uid, jointComp); } @@ -232,4 +239,4 @@ public RequestGrapplingReelMessage(bool reeling) Reeling = reeling; } } -} +} \ No newline at end of file diff --git a/Content.Shared/Weapons/Ranged/Components/GrapplingGunComponent.cs b/Content.Shared/Weapons/Ranged/Components/GrapplingGunComponent.cs index d0af3e8b36d..15f66d4c076 100644 --- a/Content.Shared/Weapons/Ranged/Components/GrapplingGunComponent.cs +++ b/Content.Shared/Weapons/Ranged/Components/GrapplingGunComponent.cs @@ -31,4 +31,4 @@ public sealed partial class GrapplingGunComponent : Component new SpriteSpecifier.Rsi(new ResPath("Objects/Weapons/Guns/Launchers/grappling_gun.rsi"), "rope"); public EntityUid? Stream; -} +} \ No newline at end of file