ctrl-rclick tweaks (#7170)

This commit is contained in:
metalgearsloth
2022-03-18 14:18:34 +11:00
committed by GitHub
parent 366503fc97
commit 867fa503fb
7 changed files with 39 additions and 209 deletions

View File

@@ -1,24 +1,8 @@
using System;
using System.Linq;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Content.Shared.GameTicking;
using Content.Shared.Input;
using Content.Shared.Physics.Pull;
using Content.Shared.Pulling.Components;
using Content.Shared.Pulling.Events;
using JetBrains.Annotations;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.Input.Binding;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Dynamics.Joints;
using Robust.Shared.Players;
using Robust.Shared.Utility;
namespace Content.Shared.Pulling
{
@@ -53,9 +37,6 @@ namespace Content.Shared.Pulling
var pullerPhysics = EntityManager.GetComponent<PhysicsComponent>(puller.Owner);
var pullablePhysics = EntityManager.GetComponent<PhysicsComponent>(pullable.Owner);
// MovingTo shutdown
ForceSetMovingTo(pullable, null);
// Joint shutdown
if (EntityManager.TryGetComponent<JointComponent?>(puller.Owner, out var jointComp))
{
@@ -153,31 +134,5 @@ namespace Content.Shared.Pulling
// DO NOT ADD ADDITIONAL LOGIC IN THIS FUNCTION. Do it in ForceRelationship.
ForceRelationship(null, pullable);
}
public void ForceSetMovingTo(SharedPullableComponent pullable, EntityCoordinates? movingTo)
{
if (pullable.MovingTo == movingTo)
{
return;
}
// Don't allow setting a MovingTo if there's no puller.
// The other half of this guarantee (shutting down a MovingTo if the puller goes away) is enforced in ForceRelationship.
if ((pullable.Puller == null) && (movingTo != null))
{
return;
}
pullable.MovingTo = movingTo;
if (movingTo == null)
{
RaiseLocalEvent(pullable.Owner, new PullableStopMovingMessage());
}
else
{
RaiseLocalEvent(pullable.Owner, new PullableMoveMessage());
}
}
}
}

View File

@@ -4,11 +4,8 @@ using Content.Shared.Physics.Pull;
using Content.Shared.Pulling.Components;
using Content.Shared.Pulling.Events;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.IoC;
using Robust.Shared.Physics;
using Robust.Shared.Log;
namespace Content.Shared.Pulling
{
@@ -29,12 +26,12 @@ namespace Content.Shared.Pulling
return false;
}
if (!EntityManager.TryGetComponent<IPhysBody?>(pulled, out var _physics))
if (!EntityManager.TryGetComponent<IPhysBody?>(pulled, out var physics))
{
return false;
}
if (_physics.BodyType == BodyType.Static)
if (physics.BodyType == BodyType.Static)
{
return false;
}
@@ -181,7 +178,7 @@ namespace Content.Shared.Pulling
return true;
}
public bool TryMoveTo(SharedPullableComponent pullable, EntityCoordinates to)
public virtual bool TryMoveTo(SharedPullableComponent pullable, EntityCoordinates to)
{
if (pullable.Puller == null)
{
@@ -193,13 +190,8 @@ namespace Content.Shared.Pulling
return false;
}
_pullSm.ForceSetMovingTo(pullable, to);
// Action handled under server
return true;
}
public void StopMoveTo(SharedPullableComponent pullable)
{
_pullSm.ForceSetMovingTo(pullable, null);
}
}
}

View File

@@ -4,6 +4,7 @@ using System.Diagnostics.CodeAnalysis;
using Content.Shared.Alert;
using Content.Shared.GameTicking;
using Content.Shared.Input;
using Content.Shared.Movement.Components;
using Content.Shared.Physics.Pull;
using Content.Shared.Pulling.Components;
using Content.Shared.Rotatable;
@@ -33,9 +34,6 @@ namespace Content.Shared.Pulling
private readonly Dictionary<EntityUid, EntityUid> _pullers =
new();
private readonly HashSet<SharedPullableComponent> _moving = new();
private readonly HashSet<SharedPullableComponent> _stoppedMoving = new();
/// <summary>
/// If distance between puller and pulled entity lower that this threshold,
/// pulled entity will not change its rotation.
@@ -51,8 +49,6 @@ namespace Content.Shared.Pulling
/// </summary>
private const float ThresholdRotAngle = 22.5f;
public IReadOnlySet<SharedPullableComponent> Moving => _moving;
public override void Initialize()
{
base.Initialize();
@@ -106,7 +102,7 @@ namespace Content.Shared.Pulling
{
if (args.Pulled.Owner != uid)
return;
_alertsSystem.ShowAlert(component.Owner, AlertType.Pulled);
}
@@ -118,19 +114,9 @@ namespace Content.Shared.Pulling
_alertsSystem.ClearAlert(component.Owner, AlertType.Pulled);
}
public override void Update(float frameTime)
{
base.Update(frameTime);
_moving.ExceptWith(_stoppedMoving);
_stoppedMoving.Clear();
}
public void Reset(RoundRestartCleanupEvent ev)
{
_pullers.Clear();
_moving.Clear();
_stoppedMoving.Clear();
}
private void OnPullStarted(PullStartedMessage message)
@@ -143,16 +129,6 @@ namespace Content.Shared.Pulling
RemovePuller(message.Puller.Owner);
}
protected void OnPullableMove(EntityUid uid, SharedPullableComponent component, PullableMoveMessage args)
{
_moving.Add(component);
}
protected void OnPullableStopMove(EntityUid uid, SharedPullableComponent component, PullableStopMovingMessage args)
{
_stoppedMoving.Add(component);
}
private void PullerMoved(ref MoveEvent ev)
{
var puller = ev.Sender;
@@ -217,6 +193,9 @@ namespace Content.Shared.Pulling
return false;
}
// No leverage until this is tweaked more
if (player.IsWeightless(entityManager: EntityManager)) return false;
TryMoveTo(pullable, coords);
return false;