Content update for NetEntities (#18935)
This commit is contained in:
@@ -341,7 +341,7 @@ namespace Content.IntegrationTests.Tests.Interaction.Click
|
||||
EntityUid target = default;
|
||||
EntityUid item = default;
|
||||
EntityUid containerEntity = default;
|
||||
IContainer container = null;
|
||||
BaseContainer container = null;
|
||||
|
||||
await server.WaitAssertion(() =>
|
||||
{
|
||||
|
||||
@@ -13,7 +13,9 @@ using Content.Server.Gravity;
|
||||
using Content.Server.Power.Components;
|
||||
using Content.Server.Tools.Components;
|
||||
using Content.Shared.Atmos;
|
||||
using Content.Shared.Construction;
|
||||
using Content.Shared.Construction.Prototypes;
|
||||
using Content.Shared.DoAfter;
|
||||
using Content.Shared.Gravity;
|
||||
using Content.Shared.Item;
|
||||
using Robust.Client.GameObjects;
|
||||
@@ -40,13 +42,15 @@ public abstract partial class InteractionTest
|
||||
|
||||
await Client.WaitPost(() =>
|
||||
{
|
||||
Assert.That(CConSys.TrySpawnGhost(proto, TargetCoords, Direction.South, out Target),
|
||||
Assert.That(CConSys.TrySpawnGhost(proto, CEntMan.GetCoordinates(TargetCoords), Direction.South, out var clientTarget),
|
||||
Is.EqualTo(shouldSucceed));
|
||||
|
||||
if (!shouldSucceed)
|
||||
return;
|
||||
var comp = CEntMan.GetComponent<ConstructionGhostComponent>(Target!.Value);
|
||||
ConstructionGhostId = comp.GhostId;
|
||||
|
||||
var comp = CEntMan.GetComponent<ConstructionGhostComponent>(clientTarget!.Value);
|
||||
ClientTarget = clientTarget;
|
||||
ConstructionGhostId = comp.Owner.Id;
|
||||
});
|
||||
|
||||
await RunTicks(1);
|
||||
@@ -61,7 +65,7 @@ public abstract partial class InteractionTest
|
||||
|
||||
// Please someone purge async construction code
|
||||
Task<bool> task = default!;
|
||||
await Server.WaitPost(() => task = SConstruction.TryStartItemConstruction(prototype, Player));
|
||||
await Server.WaitPost(() => task = SConstruction.TryStartItemConstruction(prototype, SEntMan.GetEntity(Player)));
|
||||
|
||||
Task? tickTask = null;
|
||||
while (!task.IsCompleted)
|
||||
@@ -86,10 +90,10 @@ public abstract partial class InteractionTest
|
||||
[MemberNotNull(nameof(Target))]
|
||||
protected async Task SpawnTarget(string prototype)
|
||||
{
|
||||
Target = EntityUid.Invalid;
|
||||
Target = NetEntity.Invalid;
|
||||
await Server.WaitPost(() =>
|
||||
{
|
||||
Target = SEntMan.SpawnEntity(prototype, TargetCoords);
|
||||
Target = SEntMan.GetNetEntity(SEntMan.SpawnEntity(prototype, SEntMan.GetCoordinates(TargetCoords)));
|
||||
});
|
||||
|
||||
await RunTicks(5);
|
||||
@@ -102,8 +106,9 @@ public abstract partial class InteractionTest
|
||||
protected async Task StartDeconstruction(string prototype)
|
||||
{
|
||||
await SpawnTarget(prototype);
|
||||
Assert.That(SEntMan.TryGetComponent(Target, out ConstructionComponent? comp));
|
||||
await Server.WaitPost(() => SConstruction.SetPathfindingTarget(Target!.Value, comp!.DeconstructionNode, comp));
|
||||
var serverTarget = SEntMan.GetEntity(Target);
|
||||
Assert.That(SEntMan.TryGetComponent(serverTarget, out ConstructionComponent? comp));
|
||||
await Server.WaitPost(() => SConstruction.SetPathfindingTarget(serverTarget!.Value, comp!.DeconstructionNode, comp));
|
||||
await RunTicks(5);
|
||||
}
|
||||
|
||||
@@ -116,7 +121,7 @@ public abstract partial class InteractionTest
|
||||
{
|
||||
await Server.WaitPost(() =>
|
||||
{
|
||||
Assert.That(HandSys.TryDrop(Player, null, false, true, Hands));
|
||||
Assert.That(HandSys.TryDrop(SEntMan.GetEntity(Player), null, false, true, Hands));
|
||||
SEntMan.DeleteEntity(held);
|
||||
SLogger.Debug($"Deleting held entity");
|
||||
});
|
||||
@@ -161,16 +166,18 @@ public abstract partial class InteractionTest
|
||||
}
|
||||
|
||||
// spawn and pick up the new item
|
||||
var item = await SpawnEntity(entity, PlayerCoords);
|
||||
var item = await SpawnEntity(entity, SEntMan.GetCoordinates(PlayerCoords));
|
||||
WelderComponent? welder = null;
|
||||
|
||||
await Server.WaitPost(() =>
|
||||
{
|
||||
Assert.That(HandSys.TryPickup(Player, item, Hands.ActiveHand, false, false, false, Hands));
|
||||
var playerEnt = SEntMan.GetEntity(Player);
|
||||
|
||||
Assert.That(HandSys.TryPickup(playerEnt, item, Hands.ActiveHand, false, false, false, Hands));
|
||||
|
||||
// turn on welders
|
||||
if (enableWelder && SEntMan.TryGetComponent(item, out welder) && !welder.Lit)
|
||||
Assert.That(ToolSys.TryTurnWelderOn(item, Player, welder));
|
||||
Assert.That(ToolSys.TryTurnWelderOn(item, playerEnt, welder));
|
||||
});
|
||||
|
||||
await RunTicks(1);
|
||||
@@ -184,9 +191,9 @@ public abstract partial class InteractionTest
|
||||
/// <summary>
|
||||
/// Pick up an entity. Defaults to just deleting the previously held entity.
|
||||
/// </summary>
|
||||
protected async Task Pickup(EntityUid? uid = null, bool deleteHeld = true)
|
||||
protected async Task Pickup(NetEntity? entity = null, bool deleteHeld = true)
|
||||
{
|
||||
uid ??= Target;
|
||||
entity ??= Target;
|
||||
|
||||
if (Hands.ActiveHand == null)
|
||||
{
|
||||
@@ -197,15 +204,17 @@ public abstract partial class InteractionTest
|
||||
if (deleteHeld)
|
||||
await DeleteHeldEntity();
|
||||
|
||||
var uid = SEntMan.GetEntity(entity);
|
||||
|
||||
if (!SEntMan.TryGetComponent(uid, out ItemComponent? item))
|
||||
{
|
||||
Assert.Fail($"Entity {uid} is not an item");
|
||||
Assert.Fail($"Entity {entity} is not an item");
|
||||
return;
|
||||
}
|
||||
|
||||
await Server.WaitPost(() =>
|
||||
{
|
||||
Assert.That(HandSys.TryPickup(Player, uid!.Value, Hands.ActiveHand, false, false, false, Hands, item));
|
||||
Assert.That(HandSys.TryPickup(SEntMan.GetEntity(Player), uid.Value, Hands.ActiveHand, false, false, false, Hands, item));
|
||||
});
|
||||
|
||||
await RunTicks(1);
|
||||
@@ -225,7 +234,7 @@ public abstract partial class InteractionTest
|
||||
|
||||
await Server.WaitPost(() =>
|
||||
{
|
||||
Assert.That(HandSys.TryDrop(Player, handsComp: Hands));
|
||||
Assert.That(HandSys.TryDrop(SEntMan.GetEntity(Player), handsComp: Hands));
|
||||
});
|
||||
|
||||
await RunTicks(1);
|
||||
@@ -247,7 +256,7 @@ public abstract partial class InteractionTest
|
||||
|
||||
await Server.WaitPost(() =>
|
||||
{
|
||||
InteractSys.UserInteraction(Player, SEntMan.GetComponent<TransformComponent>(target).Coordinates, target);
|
||||
InteractSys.UserInteraction(SEntMan.GetEntity(Player), SEntMan.GetComponent<TransformComponent>(target).Coordinates, target);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -274,7 +283,7 @@ public abstract partial class InteractionTest
|
||||
// (e.g., servers attempt to assemble construction examine hints).
|
||||
if (Target != null)
|
||||
{
|
||||
await Client.WaitPost(() => ExamineSys.DoExamine(Target.Value));
|
||||
await Client.WaitPost(() => ExamineSys.DoExamine(CEntMan.GetEntity(Target.Value)));
|
||||
}
|
||||
|
||||
await PlaceInHands(entity);
|
||||
@@ -286,16 +295,19 @@ public abstract partial class InteractionTest
|
||||
/// </summary>
|
||||
protected async Task Interact(bool shouldSucceed = true, bool awaitDoAfters = true)
|
||||
{
|
||||
if (Target == null || !Target.Value.IsClientSide())
|
||||
var clientTarget = ClientTarget;
|
||||
|
||||
if ((clientTarget?.IsValid() != true || CEntMan.Deleted(clientTarget)) && (Target == null || Target.Value.IsValid()))
|
||||
{
|
||||
await Server.WaitPost(() => InteractSys.UserInteraction(Player, TargetCoords, Target));
|
||||
await Server.WaitPost(() => InteractSys.UserInteraction(SEntMan.GetEntity(Player), SEntMan.GetCoordinates(TargetCoords), SEntMan.GetEntity(Target)));
|
||||
await RunTicks(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
// The entity is client-side, so attempt to start construction
|
||||
var ghost = CEntMan.GetComponent<ConstructionGhostComponent>(Target.Value);
|
||||
await Client.WaitPost(() => CConSys.TryStartConstruction(ghost.GhostId));
|
||||
var clientEnt = ClientTarget ?? CEntMan.GetEntity(Target);
|
||||
|
||||
await Client.WaitPost(() => CConSys.TryStartConstruction(clientEnt!.Value));
|
||||
await RunTicks(5);
|
||||
}
|
||||
|
||||
@@ -366,7 +378,7 @@ public abstract partial class InteractionTest
|
||||
{
|
||||
foreach (var doAfter in doAfters)
|
||||
{
|
||||
DoAfterSys.Cancel(Player, doAfter.Index, DoAfters);
|
||||
DoAfterSys.Cancel(SEntMan.GetEntity(Player), doAfter.Index, DoAfters);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -386,34 +398,33 @@ public abstract partial class InteractionTest
|
||||
/// </summary>
|
||||
protected async Task CheckTargetChange(bool shouldSucceed)
|
||||
{
|
||||
EntityUid newTarget = default;
|
||||
if (Target == null)
|
||||
return;
|
||||
var target = Target.Value;
|
||||
|
||||
var target = Target.Value;
|
||||
await RunTicks(5);
|
||||
|
||||
if (target.IsClientSide())
|
||||
if (ClientTarget != null && CEntMan.IsClientSide(ClientTarget.Value))
|
||||
{
|
||||
Assert.That(CEntMan.Deleted(target), Is.EqualTo(shouldSucceed),
|
||||
Assert.That(CEntMan.Deleted(ClientTarget.Value), Is.EqualTo(shouldSucceed),
|
||||
$"Construction ghost was {(shouldSucceed ? "not deleted" : "deleted")}.");
|
||||
|
||||
if (shouldSucceed)
|
||||
{
|
||||
Assert.That(CTestSystem.Ghosts.TryGetValue(ConstructionGhostId, out newTarget),
|
||||
Assert.That(CTestSystem.Ghosts.TryGetValue(ConstructionGhostId, out var newWeh),
|
||||
$"Failed to get construction entity from ghost Id");
|
||||
|
||||
await Client.WaitPost(() => CLogger.Debug($"Construction ghost {ConstructionGhostId} became entity {newTarget}"));
|
||||
Target = newTarget;
|
||||
await Client.WaitPost(() => CLogger.Debug($"Construction ghost {ConstructionGhostId} became entity {newWeh}"));
|
||||
Target = newWeh;
|
||||
}
|
||||
}
|
||||
|
||||
if (STestSystem.EntChanges.TryGetValue(Target.Value, out newTarget))
|
||||
if (STestSystem.EntChanges.TryGetValue(Target.Value, out var newServerWeh))
|
||||
{
|
||||
await Server.WaitPost(
|
||||
() => SLogger.Debug($"Construction entity {Target.Value} changed to {newTarget}"));
|
||||
() => SLogger.Debug($"Construction entity {Target.Value} changed to {newServerWeh}"));
|
||||
|
||||
Target = newTarget;
|
||||
Target = newServerWeh;
|
||||
}
|
||||
|
||||
if (Target != target)
|
||||
@@ -422,7 +433,7 @@ public abstract partial class InteractionTest
|
||||
|
||||
#region Asserts
|
||||
|
||||
protected void AssertPrototype(string? prototype, EntityUid? target = null)
|
||||
protected void ClientAssertPrototype(string? prototype, NetEntity? target = null)
|
||||
{
|
||||
target ??= Target;
|
||||
if (target == null)
|
||||
@@ -431,11 +442,17 @@ public abstract partial class InteractionTest
|
||||
return;
|
||||
}
|
||||
|
||||
var meta = SEntMan.GetComponent<MetaDataComponent>(target.Value);
|
||||
var meta = SEntMan.GetComponent<MetaDataComponent>(SEntMan.GetEntity(target.Value));
|
||||
Assert.That(meta.EntityPrototype?.ID, Is.EqualTo(prototype));
|
||||
}
|
||||
|
||||
protected void AssertAnchored(bool anchored = true, EntityUid? target = null)
|
||||
protected void ClientAssertPrototype(string? prototype, EntityUid? target)
|
||||
{
|
||||
var netEnt = CTestSystem.Ghosts[target.GetHashCode()];
|
||||
AssertPrototype(prototype, netEnt);
|
||||
}
|
||||
|
||||
protected void AssertPrototype(string? prototype, NetEntity? target = null)
|
||||
{
|
||||
target ??= Target;
|
||||
if (target == null)
|
||||
@@ -444,8 +461,21 @@ public abstract partial class InteractionTest
|
||||
return;
|
||||
}
|
||||
|
||||
var sXform = SEntMan.GetComponent<TransformComponent>(target.Value);
|
||||
var cXform = CEntMan.GetComponent<TransformComponent>(target.Value);
|
||||
var meta = SEntMan.GetComponent<MetaDataComponent>(SEntMan.GetEntity(target.Value));
|
||||
Assert.That(meta.EntityPrototype?.ID, Is.EqualTo(prototype));
|
||||
}
|
||||
|
||||
protected void AssertAnchored(bool anchored = true, NetEntity? target = null)
|
||||
{
|
||||
target ??= Target;
|
||||
if (target == null)
|
||||
{
|
||||
Assert.Fail("No target specified");
|
||||
return;
|
||||
}
|
||||
|
||||
var sXform = SEntMan.GetComponent<TransformComponent>(SEntMan.GetEntity(target.Value));
|
||||
var cXform = CEntMan.GetComponent<TransformComponent>(CEntMan.GetEntity(target.Value));
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
@@ -454,7 +484,7 @@ public abstract partial class InteractionTest
|
||||
});
|
||||
}
|
||||
|
||||
protected void AssertDeleted(bool deleted = true, EntityUid? target = null)
|
||||
protected void AssertDeleted(bool deleted = true, NetEntity? target = null)
|
||||
{
|
||||
target ??= Target;
|
||||
if (target == null)
|
||||
@@ -465,15 +495,15 @@ public abstract partial class InteractionTest
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(SEntMan.Deleted(target), Is.EqualTo(deleted));
|
||||
Assert.That(CEntMan.Deleted(target), Is.EqualTo(deleted));
|
||||
Assert.That(SEntMan.Deleted(SEntMan.GetEntity(target)), Is.EqualTo(deleted));
|
||||
Assert.That(CEntMan.Deleted(CEntMan.GetEntity(target)), Is.EqualTo(deleted));
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Assert whether or not the target has the given component.
|
||||
/// </summary>
|
||||
protected void AssertComp<T>(bool hasComp = true, EntityUid? target = null)
|
||||
protected void AssertComp<T>(bool hasComp = true, NetEntity? target = null)
|
||||
{
|
||||
target ??= Target;
|
||||
if (target == null)
|
||||
@@ -482,24 +512,25 @@ public abstract partial class InteractionTest
|
||||
return;
|
||||
}
|
||||
|
||||
Assert.That(SEntMan.HasComponent<T>(target), Is.EqualTo(hasComp));
|
||||
Assert.That(SEntMan.HasComponent<T>(SEntMan.GetEntity(target)), Is.EqualTo(hasComp));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check that the tile at the target position matches some prototype.
|
||||
/// </summary>
|
||||
protected async Task AssertTile(string? proto, EntityCoordinates? coords = null)
|
||||
protected async Task AssertTile(string? proto, NetCoordinates? coords = null)
|
||||
{
|
||||
var targetTile = proto == null
|
||||
? Tile.Empty
|
||||
: new Tile(TileMan[proto].TileId);
|
||||
|
||||
var tile = Tile.Empty;
|
||||
var pos = (coords ?? TargetCoords).ToMap(SEntMan, Transform);
|
||||
var serverCoords = SEntMan.GetCoordinates(coords ?? TargetCoords);
|
||||
var pos = serverCoords.ToMap(SEntMan, Transform);
|
||||
await Server.WaitPost(() =>
|
||||
{
|
||||
if (MapMan.TryFindGridAt(pos, out _, out var grid))
|
||||
tile = grid.GetTileRef(coords ?? TargetCoords).Tile;
|
||||
tile = grid.GetTileRef(serverCoords).Tile;
|
||||
});
|
||||
|
||||
Assert.That(tile.TypeId, Is.EqualTo(targetTile.TypeId));
|
||||
@@ -541,11 +572,12 @@ public abstract partial class InteractionTest
|
||||
foreach (var ent in entities)
|
||||
{
|
||||
var transform = xformQuery.GetComponent(ent);
|
||||
var netEnt = SEntMan.GetNetEntity(ent);
|
||||
|
||||
if (ent == transform.MapUid
|
||||
|| ent == transform.GridUid
|
||||
|| ent == Player
|
||||
|| ent == Target)
|
||||
|| netEnt == Player
|
||||
|| netEnt == Target)
|
||||
{
|
||||
toRemove.Add(ent);
|
||||
}
|
||||
@@ -646,31 +678,31 @@ public abstract partial class InteractionTest
|
||||
/// <summary>
|
||||
/// Convenience method to get components on the target. Returns SERVER-SIDE components.
|
||||
/// </summary>
|
||||
protected T Comp<T>(EntityUid? target = null) where T : IComponent
|
||||
protected T Comp<T>(NetEntity? target = null) where T : IComponent
|
||||
{
|
||||
target ??= Target;
|
||||
if (target == null)
|
||||
Assert.Fail("No target specified");
|
||||
|
||||
return SEntMan.GetComponent<T>(target!.Value);
|
||||
return SEntMan.GetComponent<T>(SEntMan.GetEntity(target!.Value));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the tile at the target position to some prototype.
|
||||
/// </summary>
|
||||
protected async Task SetTile(string? proto, EntityCoordinates? coords = null, MapGridComponent? grid = null)
|
||||
protected async Task SetTile(string? proto, NetCoordinates? coords = null, MapGridComponent? grid = null)
|
||||
{
|
||||
var tile = proto == null
|
||||
? Tile.Empty
|
||||
: new Tile(TileMan[proto].TileId);
|
||||
|
||||
var pos = (coords ?? TargetCoords).ToMap(SEntMan, Transform);
|
||||
var pos = SEntMan.GetCoordinates(coords ?? TargetCoords).ToMap(SEntMan, Transform);
|
||||
|
||||
await Server.WaitPost(() =>
|
||||
{
|
||||
if (grid != null || MapMan.TryFindGridAt(pos, out var gridUid, out grid))
|
||||
{
|
||||
grid.SetTile(coords ?? TargetCoords, tile);
|
||||
grid.SetTile(SEntMan.GetCoordinates(coords ?? TargetCoords), tile);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -681,7 +713,7 @@ public abstract partial class InteractionTest
|
||||
gridUid = grid.Owner;
|
||||
var gridXform = SEntMan.GetComponent<TransformComponent>(gridUid);
|
||||
Transform.SetWorldPosition(gridXform, pos.Position);
|
||||
grid.SetTile(coords ?? TargetCoords, tile);
|
||||
grid.SetTile(SEntMan.GetCoordinates(coords ?? TargetCoords), tile);
|
||||
|
||||
if (!MapMan.TryFindGridAt(pos, out _, out grid))
|
||||
Assert.Fail("Failed to create grid?");
|
||||
@@ -743,7 +775,7 @@ public abstract partial class InteractionTest
|
||||
await RunTicks(15);
|
||||
}
|
||||
|
||||
protected bool TryGetBui(Enum key, [NotNullWhen(true)] out BoundUserInterface? bui, EntityUid? target = null, bool shouldSucceed = true)
|
||||
protected bool TryGetBui(Enum key, [NotNullWhen(true)] out BoundUserInterface? bui, NetEntity? target = null, bool shouldSucceed = true)
|
||||
{
|
||||
bui = null;
|
||||
target ??= Target;
|
||||
@@ -753,17 +785,19 @@ public abstract partial class InteractionTest
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!CEntMan.TryGetComponent<ClientUserInterfaceComponent>(target, out var ui))
|
||||
var clientTarget = CEntMan.GetEntity(target);
|
||||
|
||||
if (!CEntMan.TryGetComponent<ClientUserInterfaceComponent>(clientTarget, out var ui))
|
||||
{
|
||||
if (shouldSucceed)
|
||||
Assert.Fail($"Entity {SEntMan.ToPrettyString(target.Value)} does not have a bui component");
|
||||
Assert.Fail($"Entity {SEntMan.ToPrettyString(SEntMan.GetEntity(target.Value))} does not have a bui component");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ui.OpenInterfaces.TryGetValue(key, out bui))
|
||||
{
|
||||
if (shouldSucceed)
|
||||
Assert.Fail($"Entity {SEntMan.ToPrettyString(target.Value)} does not have an open bui with key {key.GetType()}.{key}.");
|
||||
Assert.Fail($"Entity {SEntMan.ToPrettyString(SEntMan.GetEntity(target.Value))} does not have an open bui with key {key.GetType()}.{key}.");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -909,7 +943,7 @@ public abstract partial class InteractionTest
|
||||
|
||||
#region Power
|
||||
|
||||
protected void ToggleNeedPower(EntityUid? target = null)
|
||||
protected void ToggleNeedPower(NetEntity? target = null)
|
||||
{
|
||||
var comp = Comp<ApcPowerReceiverComponent>(target);
|
||||
comp.NeedsPower = !comp.NeedsPower;
|
||||
@@ -963,8 +997,8 @@ public abstract partial class InteractionTest
|
||||
protected async Task PressKey(
|
||||
BoundKeyFunction key,
|
||||
int ticks = 1,
|
||||
EntityCoordinates? coordinates = null,
|
||||
EntityUid cursorEntity = default)
|
||||
NetCoordinates? coordinates = null,
|
||||
NetEntity cursorEntity = default)
|
||||
{
|
||||
await SetKey(key, BoundKeyState.Down, coordinates, cursorEntity);
|
||||
await RunTicks(ticks);
|
||||
@@ -978,15 +1012,20 @@ public abstract partial class InteractionTest
|
||||
protected async Task SetKey(
|
||||
BoundKeyFunction key,
|
||||
BoundKeyState state,
|
||||
EntityCoordinates? coordinates = null,
|
||||
EntityUid cursorEntity = default)
|
||||
NetCoordinates? coordinates = null,
|
||||
NetEntity cursorEntity = default)
|
||||
{
|
||||
var coords = coordinates ?? TargetCoords;
|
||||
ScreenCoordinates screen = default;
|
||||
|
||||
var funcId = InputManager.NetworkBindMap.KeyFunctionID(key);
|
||||
var message = new FullInputCmdMessage(CTiming.CurTick, CTiming.TickFraction, funcId, state,
|
||||
coords, screen, cursorEntity);
|
||||
var message = new ClientFullInputCmdMessage(CTiming.CurTick, CTiming.TickFraction, funcId)
|
||||
{
|
||||
State = state,
|
||||
Coordinates = CEntMan.GetCoordinates(coords),
|
||||
ScreenCoordinates = screen,
|
||||
Uid = CEntMan.GetEntity(cursorEntity),
|
||||
};
|
||||
|
||||
await Client.WaitPost(() => InputSystem.HandleInputCommand(ClientSession, key, message));
|
||||
}
|
||||
|
||||
@@ -53,22 +53,24 @@ public abstract partial class InteractionTest
|
||||
/// Target coordinates. Note that this does not necessarily correspond to the position of the <see cref="Target"/>
|
||||
/// entity.
|
||||
/// </summary>
|
||||
protected EntityCoordinates TargetCoords;
|
||||
protected NetCoordinates TargetCoords;
|
||||
|
||||
/// <summary>
|
||||
/// Initial player coordinates. Note that this does not necessarily correspond to the position of the
|
||||
/// <see cref="Player"/> entity.
|
||||
/// </summary>
|
||||
protected EntityCoordinates PlayerCoords;
|
||||
protected NetCoordinates PlayerCoords;
|
||||
|
||||
/// <summary>
|
||||
/// The player entity that performs all these interactions. Defaults to an admin-observer with 1 hand.
|
||||
/// </summary>
|
||||
protected EntityUid Player;
|
||||
protected NetEntity Player;
|
||||
|
||||
protected ICommonSession ClientSession = default!;
|
||||
protected IPlayerSession ServerSession = default!;
|
||||
|
||||
public EntityUid? ClientTarget;
|
||||
|
||||
/// <summary>
|
||||
/// The current target entity. This is the default entity for various helper functions.
|
||||
/// </summary>
|
||||
@@ -77,7 +79,7 @@ public abstract partial class InteractionTest
|
||||
/// interactions often swap out entities, and there are helper methods that attempt to automatically upddate
|
||||
/// the target entity. See <see cref="CheckTargetChange"/>
|
||||
/// </remarks>
|
||||
protected EntityUid? Target;
|
||||
protected NetEntity? Target;
|
||||
|
||||
/// <summary>
|
||||
/// When attempting to start construction, this is the client-side ID of the construction ghost.
|
||||
@@ -174,8 +176,8 @@ public abstract partial class InteractionTest
|
||||
|
||||
// Setup map.
|
||||
await Pair.CreateTestMap();
|
||||
PlayerCoords = MapData.GridCoords.Offset(new Vector2(0.5f, 0.5f)).WithEntityId(MapData.MapUid, Transform, SEntMan);
|
||||
TargetCoords = MapData.GridCoords.Offset(new Vector2(1.5f, 0.5f)).WithEntityId(MapData.MapUid, Transform, SEntMan);
|
||||
PlayerCoords = SEntMan.GetNetCoordinates(MapData.GridCoords.Offset(new Vector2(0.5f, 0.5f)).WithEntityId(MapData.MapUid, Transform, SEntMan));
|
||||
TargetCoords = SEntMan.GetNetCoordinates(MapData.GridCoords.Offset(new Vector2(1.5f, 0.5f)).WithEntityId(MapData.MapUid, Transform, SEntMan));
|
||||
await SetTile(Plating, grid: MapData.MapGrid);
|
||||
|
||||
// Get player data
|
||||
@@ -195,15 +197,16 @@ public abstract partial class InteractionTest
|
||||
SEntMan.System<SharedMindSystem>().WipeMind(ServerSession.ContentData()?.Mind);
|
||||
|
||||
old = cPlayerMan.LocalPlayer.ControlledEntity;
|
||||
Player = SEntMan.SpawnEntity(PlayerPrototype, PlayerCoords);
|
||||
Actor.Attach(Player, ServerSession);
|
||||
Hands = SEntMan.GetComponent<HandsComponent>(Player);
|
||||
DoAfters = SEntMan.GetComponent<DoAfterComponent>(Player);
|
||||
Player = SEntMan.GetNetEntity(SEntMan.SpawnEntity(PlayerPrototype, SEntMan.GetCoordinates(PlayerCoords)));
|
||||
var serverPlayerEnt = SEntMan.GetEntity(Player);
|
||||
Actor.Attach(serverPlayerEnt, ServerSession);
|
||||
Hands = SEntMan.GetComponent<HandsComponent>(serverPlayerEnt);
|
||||
DoAfters = SEntMan.GetComponent<DoAfterComponent>(serverPlayerEnt);
|
||||
});
|
||||
|
||||
// Check player got attached.
|
||||
await RunTicks(5);
|
||||
Assert.That(cPlayerMan.LocalPlayer.ControlledEntity, Is.EqualTo(Player));
|
||||
Assert.That(CEntMan.GetNetEntity(cPlayerMan.LocalPlayer.ControlledEntity), Is.EqualTo(Player));
|
||||
|
||||
// Delete old player entity.
|
||||
await Server.WaitPost(() =>
|
||||
@@ -216,7 +219,7 @@ public abstract partial class InteractionTest
|
||||
await Server.WaitPost(() =>
|
||||
{
|
||||
var bodySystem = SEntMan.System<BodySystem>();
|
||||
var hands = bodySystem.GetBodyChildrenOfType(Player, BodyPartType.Hand).ToArray();
|
||||
var hands = bodySystem.GetBodyChildrenOfType(SEntMan.GetEntity(Player), BodyPartType.Hand).ToArray();
|
||||
|
||||
for (var i = 1; i < hands.Length; i++)
|
||||
{
|
||||
@@ -229,8 +232,8 @@ public abstract partial class InteractionTest
|
||||
await Pair.ReallyBeIdle(5);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(cPlayerMan.LocalPlayer.ControlledEntity, Is.EqualTo(Player));
|
||||
Assert.That(sPlayerMan.GetSessionByUserId(ClientSession.UserId).AttachedEntity, Is.EqualTo(Player));
|
||||
Assert.That(CEntMan.GetNetEntity(cPlayerMan.LocalPlayer.ControlledEntity), Is.EqualTo(Player));
|
||||
Assert.That(sPlayerMan.GetSessionByUserId(ClientSession.UserId).AttachedEntity, Is.EqualTo(SEntMan.GetEntity(Player)));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -12,8 +12,8 @@ namespace Content.IntegrationTests.Tests.Interaction;
|
||||
/// </summary>
|
||||
public sealed class InteractionTestSystem : EntitySystem
|
||||
{
|
||||
public Dictionary<int, EntityUid> Ghosts = new();
|
||||
public Dictionary<EntityUid, EntityUid> EntChanges = new();
|
||||
public Dictionary<int, NetEntity> Ghosts = new();
|
||||
public Dictionary<NetEntity, NetEntity> EntChanges = new();
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -23,7 +23,8 @@ public sealed class InteractionTestSystem : EntitySystem
|
||||
|
||||
private void OnEntChange(ConstructionChangeEntityEvent ev)
|
||||
{
|
||||
EntChanges[ev.Old] = ev.New;
|
||||
Assert.That(!IsClientSide(ev.Old) && !IsClientSide(ev.New));
|
||||
EntChanges[GetNetEntity(ev.Old)] = GetNetEntity(ev.New);
|
||||
}
|
||||
|
||||
private void OnAck(AckStructureConstructionMessage ev)
|
||||
|
||||
@@ -27,16 +27,18 @@ public abstract class MovementTest : InteractionTest
|
||||
public override async Task Setup()
|
||||
{
|
||||
await base.Setup();
|
||||
var pCoords = SEntMan.GetCoordinates(PlayerCoords);
|
||||
|
||||
for (var i = -Tiles; i <= Tiles; i++)
|
||||
{
|
||||
await SetTile(Plating, PlayerCoords.Offset(new Vector2(i, 0)), MapData.MapGrid);
|
||||
await SetTile(Plating, SEntMan.GetNetCoordinates(pCoords.Offset(new Vector2(i, 0))), MapData.MapGrid);
|
||||
}
|
||||
AssertGridCount(1);
|
||||
|
||||
if (AddWalls)
|
||||
{
|
||||
await SpawnEntity("WallSolid", PlayerCoords.Offset(new Vector2(-Tiles, 0)));
|
||||
await SpawnEntity("WallSolid", PlayerCoords.Offset(new Vector2(Tiles, 0)));
|
||||
await SpawnEntity("WallSolid", pCoords.Offset(new Vector2(-Tiles, 0)));
|
||||
await SpawnEntity("WallSolid", pCoords.Offset(new Vector2(Tiles, 0)));
|
||||
}
|
||||
|
||||
await AddGravity();
|
||||
@@ -46,7 +48,7 @@ public abstract class MovementTest : InteractionTest
|
||||
/// <summary>
|
||||
/// Get the relative horizontal between two entities. Defaults to using the target & player entity.
|
||||
/// </summary>
|
||||
protected float Delta(EntityUid? target = null, EntityUid? other = null)
|
||||
protected float Delta(NetEntity? target = null, NetEntity? other = null)
|
||||
{
|
||||
target ??= Target;
|
||||
if (target == null)
|
||||
@@ -55,7 +57,7 @@ public abstract class MovementTest : InteractionTest
|
||||
return 0;
|
||||
}
|
||||
|
||||
var delta = Transform.GetWorldPosition(target.Value) - Transform.GetWorldPosition(other ?? Player);
|
||||
var delta = Transform.GetWorldPosition(SEntMan.GetEntity(target.Value)) - Transform.GetWorldPosition(SEntMan.GetEntity(other ?? Player));
|
||||
return delta.X;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user