Adds grappling gun (#16662)
This commit is contained in:
74
Content.Client/Physics/JointVisualsOverlay.cs
Normal file
74
Content.Client/Physics/JointVisualsOverlay.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
using Content.Shared.Physics;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Shared.Enums;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Dynamics.Joints;
|
||||
|
||||
namespace Content.Client.Physics;
|
||||
|
||||
/// <summary>
|
||||
/// Draws a texture on top of a joint.
|
||||
/// </summary>
|
||||
public sealed class JointVisualsOverlay : Overlay
|
||||
{
|
||||
public override OverlaySpace Space => OverlaySpace.WorldSpaceBelowFOV;
|
||||
|
||||
private IEntityManager _entManager;
|
||||
|
||||
private HashSet<Joint> _drawn = new();
|
||||
|
||||
public JointVisualsOverlay(IEntityManager entManager)
|
||||
{
|
||||
_entManager = entManager;
|
||||
}
|
||||
|
||||
protected override void Draw(in OverlayDrawArgs args)
|
||||
{
|
||||
_drawn.Clear();
|
||||
var worldHandle = args.WorldHandle;
|
||||
|
||||
var spriteSystem = _entManager.System<SpriteSystem>();
|
||||
var xformSystem = _entManager.System<SharedTransformSystem>();
|
||||
var joints = _entManager.EntityQueryEnumerator<JointVisualsComponent, TransformComponent>();
|
||||
var xformQuery = _entManager.GetEntityQuery<TransformComponent>();
|
||||
|
||||
while (joints.MoveNext(out var visuals, out var xform))
|
||||
{
|
||||
if (xform.MapID != args.MapId)
|
||||
continue;
|
||||
|
||||
var other = visuals.Target;
|
||||
|
||||
if (!xformQuery.TryGetComponent(other, out var otherXform))
|
||||
continue;
|
||||
|
||||
if (xform.MapID != otherXform.MapID)
|
||||
continue;
|
||||
|
||||
var texture = spriteSystem.Frame0(visuals.Sprite);
|
||||
var width = texture.Width / (float) EyeManager.PixelsPerMeter;
|
||||
|
||||
var coordsA = xform.Coordinates;
|
||||
var coordsB = otherXform.Coordinates;
|
||||
|
||||
var rotA = xform.LocalRotation;
|
||||
var rotB = otherXform.LocalRotation;
|
||||
|
||||
coordsA = coordsA.Offset(rotA.RotateVec(visuals.OffsetA));
|
||||
coordsB = coordsB.Offset(rotB.RotateVec(visuals.OffsetB));
|
||||
|
||||
var posA = coordsA.ToMapPos(_entManager, xformSystem);
|
||||
var posB = coordsB.ToMapPos(_entManager, xformSystem);
|
||||
var diff = (posB - posA);
|
||||
var length = diff.Length;
|
||||
|
||||
var midPoint = diff / 2f + posA;
|
||||
var angle = (posB - posA).ToWorldAngle();
|
||||
var box = new Box2(-width / 2f, -length / 2f, width / 2f, length / 2f);
|
||||
var rotate = new Box2Rotated(box.Translated(midPoint), angle, midPoint);
|
||||
|
||||
worldHandle.DrawTextureRect(texture, rotate);
|
||||
}
|
||||
}
|
||||
}
|
||||
20
Content.Client/Physics/JointVisualsSystem.cs
Normal file
20
Content.Client/Physics/JointVisualsSystem.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using Robust.Client.Graphics;
|
||||
|
||||
namespace Content.Client.Physics;
|
||||
|
||||
public sealed class JointVisualsSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IOverlayManager _overlay = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
_overlay.AddOverlay(new JointVisualsOverlay(EntityManager));
|
||||
}
|
||||
|
||||
public override void Shutdown()
|
||||
{
|
||||
base.Shutdown();
|
||||
_overlay.RemoveOverlay<JointVisualsOverlay>();
|
||||
}
|
||||
}
|
||||
58
Content.Client/Weapons/Misc/GrapplingGunSystem.cs
Normal file
58
Content.Client/Weapons/Misc/GrapplingGunSystem.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using System.Net;
|
||||
using Content.Client.Hands.Systems;
|
||||
using Content.Shared.CombatMode;
|
||||
using Content.Shared.Weapons.Misc;
|
||||
using Content.Shared.Weapons.Ranged.Components;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.Player;
|
||||
using Robust.Shared.Input;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Dynamics.Joints;
|
||||
|
||||
namespace Content.Client.Weapons.Misc;
|
||||
|
||||
public sealed class GrapplingGunSystem : SharedGrapplingGunSystem
|
||||
{
|
||||
[Dependency] private readonly HandsSystem _hands = default!;
|
||||
[Dependency] private readonly InputSystem _input = default!;
|
||||
[Dependency] private readonly IPlayerManager _player = default!;
|
||||
|
||||
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;
|
||||
|
||||
var local = _player.LocalPlayer?.ControlledEntity;
|
||||
var handUid = _hands.GetActiveHandEntity();
|
||||
|
||||
if (!TryComp<GrapplingGunComponent>(handUid, out var grappling))
|
||||
return;
|
||||
|
||||
if (!TryComp<JointComponent>(handUid, out var jointComp) ||
|
||||
!jointComp.GetJoints.TryGetValue(GrapplingJoint, out var joint) ||
|
||||
joint is not DistanceJoint distance)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (distance.MaxLength <= distance.MinLength)
|
||||
return;
|
||||
|
||||
var reelKey = _input.CmdStates.GetState(EngineKeyFunctions.UseSecondary) == BoundKeyState.Down;
|
||||
|
||||
if (!TryComp<CombatModeComponent>(local, out var combatMode) ||
|
||||
!combatMode.IsInCombatMode)
|
||||
{
|
||||
reelKey = false;
|
||||
}
|
||||
|
||||
if (grappling.Reeling == reelKey)
|
||||
return;
|
||||
|
||||
RaisePredictiveEvent(new RequestGrapplingReelMessage(reelKey));
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using Content.Shared.Weapons.Ranged.Components;
|
||||
using Content.Shared.Weapons.Ranged.Events;
|
||||
using Robust.Shared.Map;
|
||||
|
||||
namespace Content.Client.Weapons.Ranged.Systems;
|
||||
@@ -19,9 +20,10 @@ public sealed partial class GunSystem
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Cycle(BallisticAmmoProviderComponent component, MapCoordinates coordinates)
|
||||
protected override void Cycle(EntityUid uid, BallisticAmmoProviderComponent component, MapCoordinates coordinates)
|
||||
{
|
||||
if (!Timing.IsFirstTimePredicted) return;
|
||||
if (!Timing.IsFirstTimePredicted)
|
||||
return;
|
||||
|
||||
EntityUid? ent = null;
|
||||
|
||||
@@ -43,5 +45,8 @@ public sealed partial class GunSystem
|
||||
|
||||
if (ent != null && ent.Value.IsClientSide())
|
||||
Del(ent.Value);
|
||||
|
||||
var cycledEvent = new GunCycledEvent();
|
||||
RaiseLocalEvent(uid, ref cycledEvent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,8 +173,10 @@ public sealed partial class GunSystem : SharedGunSystem
|
||||
}
|
||||
|
||||
public override void Shoot(EntityUid gunUid, GunComponent gun, List<(EntityUid? Entity, IShootable Shootable)> ammo,
|
||||
EntityCoordinates fromCoordinates, EntityCoordinates toCoordinates, EntityUid? user = null, bool throwItems = false)
|
||||
EntityCoordinates fromCoordinates, EntityCoordinates toCoordinates, out bool userImpulse, EntityUid? user = null, bool throwItems = false)
|
||||
{
|
||||
userImpulse = true;
|
||||
|
||||
// Rather than splitting client / server for every ammo provider it's easier
|
||||
// to just delete the spawned entities. This is for programmer sanity despite the wasted perf.
|
||||
// This also means any ammo specific stuff can be grabbed as necessary.
|
||||
@@ -207,6 +209,7 @@ public sealed partial class GunSystem : SharedGunSystem
|
||||
}
|
||||
else
|
||||
{
|
||||
userImpulse = false;
|
||||
Audio.PlayPredicted(gun.SoundEmpty, gunUid, user);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user