Files
tbd-station-14/Content.Shared/Weapons/Misc/SharedTetherGunSystem.Force.cs
Nemanja a1a8f04036 Decouple interactions from hands, cleanup old events, add new fears (#28393)
* ok basic shit

* second part

* pretend it isn't real it can't hurt you.

* 👁️ 👁️

* shadowcommander review
2024-05-31 13:26:19 -07:00

59 lines
1.8 KiB
C#

using System.Numerics;
using Content.Shared.Interaction;
using Robust.Shared.Map;
namespace Content.Shared.Weapons.Misc;
public abstract partial class SharedTetherGunSystem
{
private void InitializeForce()
{
SubscribeLocalEvent<ForceGunComponent, AfterInteractEvent>(OnForceRanged);
SubscribeLocalEvent<ForceGunComponent, ActivateInWorldEvent>(OnForceActivate);
}
private void OnForceActivate(EntityUid uid, ForceGunComponent component, ActivateInWorldEvent args)
{
if (!args.Complex)
return;
StopTether(uid, component);
}
private void OnForceRanged(EntityUid uid, ForceGunComponent component, AfterInteractEvent args)
{
if (IsTethered(component))
{
if (!args.ClickLocation.TryDistance(EntityManager, TransformSystem, Transform(uid).Coordinates,
out var distance) ||
distance > component.ThrowDistance)
{
return;
}
// URGH, soon
// Need auto states to be nicer + powercelldraw to be nicer
if (!_netManager.IsServer)
return;
// Launch
var tethered = component.Tethered;
StopTether(uid, component, land: false);
_throwing.TryThrow(tethered!.Value, args.ClickLocation, component.ThrowForce, playSound: false);
_audio.PlayPredicted(component.LaunchSound, uid, null);
}
else if (args.Target != null)
{
// Pickup
if (TryTether(uid, args.Target.Value, args.User, component))
TransformSystem.SetCoordinates(component.TetherEntity!.Value, new EntityCoordinates(uid, new Vector2(0f, 0f)));
}
}
private bool IsTethered(ForceGunComponent component)
{
return component.Tethered != null;
}
}