Tether gun fixes (#8129)

This commit is contained in:
metalgearsloth
2022-05-13 18:59:12 +10:00
committed by GitHub
parent bc68ac96dd
commit 2c927bb24e
6 changed files with 80 additions and 13 deletions

View File

@@ -9,6 +9,12 @@ public sealed class TetherGunCommand : IConsoleCommand
public string Help => $"{Command}";
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<TetherGunSystem>().Enabled ^= true;
var system = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<TetherGunSystem>();
system.Enabled ^= true;
if (system.Enabled)
shell.WriteLine("Tether gun toggled on");
else
shell.WriteLine("Tether gun toggled off");
}
}

View File

@@ -23,9 +23,36 @@ public sealed class TetherGunSystem : SharedTetherGunSystem
/// The entity being dragged around.
/// </summary>
private EntityUid? _dragging;
private EntityUid? _tether;
private MapCoordinates? _lastMousePosition;
public override void Initialize()
{
base.Initialize();
SubscribeNetworkEvent<PredictTetherEvent>(OnPredictTether);
}
private void OnPredictTether(PredictTetherEvent ev)
{
if (_dragging != ev.Entity) return;
_tether = ev.Entity;
}
public override void FrameUpdate(float frameTime)
{
base.FrameUpdate(frameTime);
if (!TryComp<PhysicsComponent>(_dragging, out var body)) return;
body.Predict = true;
if (TryComp<PhysicsComponent>(_tether, out var tetherBody))
{
tetherBody.Predict = true;
}
}
public override void Update(float frameTime)
{
base.Update(frameTime);
@@ -46,18 +73,18 @@ public sealed class TetherGunSystem : SharedTetherGunSystem
if (_dragging == null)
{
var bodyQuery = GetEntityQuery<PhysicsComponent>();
var lowest = new List<(int DrawDepth, EntityUid Entity)>();
var lowest = new List<(int DrawDepth, uint RenderOrder, EntityUid Entity)>();
foreach (var ent in _lookup.GetEntitiesIntersecting(mousePos))
foreach (var ent in _lookup.GetEntitiesIntersecting(mousePos, LookupFlags.Approximate | LookupFlags.Anchored))
{
if (!bodyQuery.HasComponent(ent) ||
!TryComp<ClickableComponent>(ent, out var clickable) ||
!clickable.CheckClick(mousePos.Position, out var drawDepth, out _)) continue;
!clickable.CheckClick(mousePos.Position, out var drawDepth, out var renderOrder)) continue;
lowest.Add((drawDepth, ent));
lowest.Add((drawDepth, renderOrder, ent));
}
lowest.Sort((x, y) => y.DrawDepth.CompareTo(x.DrawDepth));
lowest.Sort((x, y) => y.DrawDepth == x.DrawDepth ? y.RenderOrder.CompareTo(x.RenderOrder) : y.DrawDepth.CompareTo(x.DrawDepth));
foreach (var ent in lowest)
{
@@ -69,12 +96,20 @@ public sealed class TetherGunSystem : SharedTetherGunSystem
}
if (!TryComp<TransformComponent>(_dragging!.Value, out var xform) ||
_lastMousePosition!.Value.MapId != xform.MapID)
_lastMousePosition!.Value.MapId != xform.MapID ||
!TryComp<PhysicsComponent>(_dragging, out var body))
{
StopDragging();
return;
}
body.Predict = true;
if (TryComp<PhysicsComponent>(_tether, out var tetherBody))
{
tetherBody.Predict = true;
}
if (_lastMousePosition.Value.Position.EqualsApprox(mousePos.Position)) return;
_lastMousePosition = mousePos;
@@ -92,6 +127,7 @@ public sealed class TetherGunSystem : SharedTetherGunSystem
RaiseNetworkEvent(new StopTetherEvent());
_dragging = null;
_lastMousePosition = null;
_tether = null;
}
private void StartDragging(EntityUid uid, MapCoordinates coordinates)