Add some tests and fix some miscellaneous bugs (#22836)

* Add some tests and fix some bugs

* Add more helper methods

* remove submodule

* fix merge

* also fix DirtyAll()

* poke
This commit is contained in:
Leon Friedrich
2023-12-27 18:05:20 -05:00
committed by GitHub
parent 44adc32613
commit 35ba42af9c
14 changed files with 292 additions and 37 deletions

View File

@@ -34,7 +34,7 @@ namespace Content.Server.Hands.Systems
{
base.Initialize();
SubscribeLocalEvent<HandsComponent, DisarmedEvent>(OnDisarmed, before: new[] { typeof(StunSystem) });
SubscribeLocalEvent<HandsComponent, DisarmedEvent>(OnDisarmed, before: new[] {typeof(StunSystem)});
SubscribeLocalEvent<HandsComponent, PullStartedMessage>(HandlePullStarted);
SubscribeLocalEvent<HandsComponent, PullStoppedMessage>(HandlePullStopped);
@@ -67,7 +67,7 @@ namespace Content.Server.Hands.Systems
{
foreach (var hand in ent.Comp.Hands.Values)
{
if (hand.HeldEntity is {} uid)
if (hand.HeldEntity is { } uid)
args.Contents.Add(uid);
}
}
@@ -78,7 +78,8 @@ namespace Content.Server.Hands.Systems
return;
// Break any pulls
if (TryComp(uid, out SharedPullerComponent? puller) && puller.Pulling is EntityUid pulled && TryComp(pulled, out SharedPullableComponent? pullable))
if (TryComp(uid, out SharedPullerComponent? puller) && puller.Pulling is EntityUid pulled &&
TryComp(pulled, out SharedPullableComponent? pullable))
_pullingSystem.TryStopPull(pullable);
if (!_handsSystem.TryDrop(uid, component.ActiveHand!, null, checkActionBlocker: false))
@@ -114,6 +115,7 @@ namespace Content.Server.Hands.Systems
}
#region pulling
private void HandlePullStarted(EntityUid uid, HandsComponent component, PullStartedMessage args)
{
if (args.Puller.Owner != uid)
@@ -146,17 +148,25 @@ namespace Content.Server.Hands.Systems
break;
}
}
#endregion
#region interactions
private bool HandleThrowItem(ICommonSession? playerSession, EntityCoordinates coordinates, EntityUid entity)
{
if (playerSession == null)
if (playerSession?.AttachedEntity is not {Valid: true} player || !Exists(player))
return false;
if (playerSession.AttachedEntity is not {Valid: true} player ||
!Exists(player) ||
ContainerSystem.IsEntityInContainer(player) ||
return ThrowHeldItem(player, coordinates);
}
/// <summary>
/// Throw the player's currently held item.
/// </summary>
public bool ThrowHeldItem(EntityUid player, EntityCoordinates coordinates, float minDistance = 0.1f)
{
if (ContainerSystem.IsEntityInContainer(player) ||
!TryComp(player, out HandsComponent? hands) ||
hands.ActiveHandEntity is not { } throwEnt ||
!_actionBlockerSystem.CanThrow(player, throwEnt))
@@ -176,7 +186,9 @@ namespace Content.Server.Hands.Systems
if (direction == Vector2.Zero)
return true;
direction = direction.Normalized() * Math.Min(direction.Length(), hands.ThrowRange);
var length = direction.Length();
var distance = Math.Clamp(length, minDistance, hands.ThrowRange);
direction *= distance/length;
var throwStrength = hands.ThrowForceMultiplier;