Skip to content
This repository has been archived by the owner on Nov 1, 2024. It is now read-only.

Commit

Permalink
ГрапплингХук
Browse files Browse the repository at this point in the history
  • Loading branch information
Vonsant committed Jun 20, 2024
1 parent aa1ee7b commit 0bcc91a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
7 changes: 1 addition & 6 deletions Content.Client/Weapons/Misc/GrapplingGunSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<CombatModeComponent>(local, out var combatMode) ||
Expand All @@ -55,4 +50,4 @@ public override void Update(float frameTime)

RaisePredictiveEvent(new RequestGrapplingReelMessage(reelKey));
}
}
}
29 changes: 18 additions & 11 deletions Content.Shared/Weapons/Misc/SharedGrapplingGunSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -59,8 +60,6 @@ private void OnGrapplingShot(EntityUid uid, GrapplingGunComponent component, ref
if (!HasComp<GrapplingProjectileComponent>(shotUid))
continue;

//todo: this doesn't actually support multigrapple
// At least show the visuals.
component.Projectile = shotUid.Value;
Dirty(uid, component);
var visuals = EnsureComp<JointVisualsComponent>(shotUid.Value);
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -171,7 +170,6 @@ public override void Update(float frameTime)
{
if (Timing.IsFirstTimePredicted)
{
// Just in case.
grappling.Stream = _audio.Stop(grappling.Stream);
}

Expand All @@ -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);
Expand All @@ -214,11 +223,9 @@ private void OnGrappleCollide(EntityUid uid, GrapplingProjectileComponent compon

var jointComp = EnsureComp<JointComponent>(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);
}

Expand All @@ -232,4 +239,4 @@ public RequestGrapplingReelMessage(bool reeling)
Reeling = reeling;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit 0bcc91a

Please sign in to comment.