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

@@ -38,9 +38,9 @@ public sealed class DirtyCommand : IConsoleCommand
private static void DirtyAll(IEntityManager manager, EntityUid entityUid)
{
foreach (var component in manager.GetComponents(entityUid))
foreach (var component in manager.GetNetComponents(entityUid))
{
manager.Dirty((Component)component);
manager.Dirty(entityUid, component.component);
}
}
}

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;

View File

@@ -312,7 +312,7 @@ public sealed class SpreaderSystem : EntitySystem
if (position == null)
{
var transform = Transform(uid);
if (!_mapManager.TryGetGrid(transform.GridUid, out grid))
if (!_mapManager.TryGetGrid(transform.GridUid, out grid) || TerminatingOrDeleted(transform.GridUid.Value))
return neighbors;
tile = grid.TileIndicesFor(transform.Coordinates);
}
@@ -337,7 +337,7 @@ public sealed class SpreaderSystem : EntitySystem
while (directionEnumerator.MoveNext(out var ent))
{
DebugTools.Assert(Transform(ent.Value).Anchored);
if (spreaderQuery.HasComponent(ent))
if (spreaderQuery.HasComponent(ent) && !TerminatingOrDeleted(ent.Value))
neighbors.Add(ent.Value);
}
}