protected sealed override ClientIntegrationInstance StartClient(ClientIntegrationOptions options = null) { options ??= new ClientIntegrationOptions(); // ReSharper disable once RedundantNameQualifier options.ContentAssemblies = new[] { typeof(Shared.EntryPoint).Assembly, typeof(Client.EntryPoint).Assembly, typeof(ContentIntegrationTest).Assembly }; options.BeforeStart += () => { IoCManager.Resolve <IModLoader>().SetModuleBaseCallbacks(new ClientModuleTestingCallbacks { ClientBeforeIoC = () => { if (options is ClientContentIntegrationOption contentOptions) { contentOptions.ContentBeforeIoC?.Invoke(); } IoCManager.Register <IParallaxManager, DummyParallaxManager>(true); } }); };
private async Task <(ClientIntegrationInstance c, ServerIntegrationInstance s)> Start() { var optsServer = new ServerIntegrationOptions { CVarOverrides = { { CVars.NetPVS.Name, "false" } }, ExtraPrototypes = ExtraPrototypes }; var optsClient = new ClientIntegrationOptions { CVarOverrides = { { CVars.NetPVS.Name, "false" } }, ExtraPrototypes = ExtraPrototypes }; var(c, s) = await StartConnectedServerDummyTickerClientPair(optsClient, optsServer); s.Post(() => { IoCManager.Resolve <IPlayerManager>() .GetAllPlayers() .Single() .JoinGame(); var mapMan = IoCManager.Resolve <IMapManager>(); mapMan.CreateMap(new MapId(1)); }); return(c, s); }
protected sealed override ClientIntegrationInstance StartClient(ClientIntegrationOptions options = null) { options ??= new ClientContentIntegrationOption() { FailureLogLevel = LogLevel.Warning }; options.ContentAssemblies = new[] { typeof(Shared.EntryPoint).Assembly, typeof(Client.EntryPoint).Assembly, typeof(ContentIntegrationTest).Assembly }; options.BeforeStart += () => { IoCManager.Resolve <IModLoader>().SetModuleBaseCallbacks(new ClientModuleTestingCallbacks { ClientBeforeIoC = () => { if (options is ClientContentIntegrationOption contentOptions) { contentOptions.ContentBeforeIoC?.Invoke(); } IoCManager.Register <IParallaxManager, DummyParallaxManager>(true); IoCManager.Resolve <ILogManager>().GetSawmill("loc").Level = LogLevel.Error; } }); };
protected sealed override ClientIntegrationInstance StartClient(ClientIntegrationOptions options = null) { options ??= new ClientContentIntegrationOption(); // Load content resources, but not config and user data. options.Options = new GameControllerOptions() { LoadContentResources = true, LoadConfigAndUserData = false, }; options.ContentStart = true; options.ContentAssemblies = new[] { typeof(OpenDreamShared.EntryPoint).Assembly, typeof(OpenDreamClient.EntryPoint).Assembly, typeof(ContentIntegrationTest).Assembly }; options.BeforeStart += () => { IoCManager.Resolve <IModLoader>().SetModuleBaseCallbacks(new ClientModuleTestingCallbacks { ClientBeforeIoC = () => { IoCManager.Register <IDreamInterfaceManager, DummyDreamInterfaceManager>(true); if (options is ClientContentIntegrationOption contentOptions) { contentOptions.ContentBeforeIoC?.Invoke(); } } }); };
internal ClientIntegrationInstance(ClientIntegrationOptions options) { _options = options; InstanceThread = new Thread(_clientMain) { Name = "Client Instance Thread" }; DependencyCollection = new DependencyCollection(); InstanceThread.Start(); }
protected override ClientIntegrationInstance StartClient(ClientIntegrationOptions options = null) { options = options ?? new ClientIntegrationOptions(); options.BeforeStart += () => { // Connecting to Discord is a massive waste of time. // Basically just makes the CI logs a mess. IoCManager.Resolve <IConfigurationManager>().SetCVar("discord.enabled", false); IoCManager.Resolve <IModLoader>().SetModuleBaseCallbacks(new ClientModuleTestingCallbacks { ClientBeforeIoC = () => { IoCManager.Register <IParallaxManager, DummyParallaxManager>(true); } }); }; return(base.StartClient(options)); }
protected override ClientIntegrationInstance StartClient(ClientIntegrationOptions options = null) { options ??= new ClientIntegrationOptions(); // ReSharper disable once RedundantNameQualifier options.ClientContentAssembly = typeof(EntryPoint).Assembly; options.SharedContentAssembly = typeof(Shared.EntryPoint).Assembly; options.BeforeStart += () => { // Connecting to Discord is a massive waste of time. // Basically just makes the CI logs a mess. IoCManager.Resolve <IConfigurationManager>().SetCVar("discord.enabled", false); IoCManager.Resolve <IModLoader>().SetModuleBaseCallbacks(new ClientModuleTestingCallbacks { ClientBeforeIoC = () => { IoCManager.Register <IParallaxManager, DummyParallaxManager>(true); } }); }; return(base.StartClient(options)); }
protected sealed override ClientIntegrationInstance StartClient(ClientIntegrationOptions options = null) { options ??= new ClientContentIntegrationOption() { FailureLogLevel = LogLevel.Warning }; // Load content resources, but not config and user data. options.Options = new GameControllerOptions() { LoadContentResources = true, LoadConfigAndUserData = false, }; options.ContentStart = true; options.ContentAssemblies = new[] { typeof(Shared.Entry.EntryPoint).Assembly, typeof(EntryPoint).Assembly, typeof(ContentIntegrationTest).Assembly }; options.BeforeStart += () => { IoCManager.Resolve <IModLoader>().SetModuleBaseCallbacks(new ClientModuleTestingCallbacks { ClientBeforeIoC = () => { if (options is ClientContentIntegrationOption contentOptions) { contentOptions.ContentBeforeIoC?.Invoke(); } IoCManager.Register <IParallaxManager, DummyParallaxManager>(true); IoCManager.Resolve <ILogManager>().GetSawmill("loc").Level = LogLevel.Error; } }); };
public async Task GrantsAndRevokesItemActions() { var serverOptions = new ServerIntegrationOptions { ExtraPrototypes = PROTOTYPES }; var clientOptions = new ClientIntegrationOptions { ExtraPrototypes = PROTOTYPES }; var(client, server) = await StartConnectedServerClientPair(serverOptions : serverOptions, clientOptions : clientOptions); await server.WaitIdleAsync(); await client.WaitIdleAsync(); var serverPlayerManager = server.ResolveDependency <Robust.Server.Interfaces.Player.IPlayerManager>(); var serverEntManager = server.ResolveDependency <IEntityManager>(); var serverGameTiming = server.ResolveDependency <IGameTiming>(); var cooldown = Cooldowns.SecondsFromNow(30, serverGameTiming); ServerActionsComponent serverActionsComponent = null; ClientActionsComponent clientActionsComponent = null; IEntity serverPlayerEnt = null; IEntity serverFlashlight = null; await server.WaitAssertion(() => { serverPlayerEnt = serverPlayerManager.GetAllPlayers().Single().AttachedEntity; serverActionsComponent = serverPlayerEnt.GetComponent <ServerActionsComponent>(); // spawn and give them an item that has actions serverFlashlight = serverEntManager.SpawnEntity("TestFlashlight", new EntityCoordinates(new EntityUid(1), (0, 0))); Assert.That(serverFlashlight.TryGetComponent <ItemActionsComponent>(out var itemActions)); // we expect this only to have a toggle light action initially var actionConfigs = itemActions.ActionConfigs.ToList(); Assert.That(actionConfigs.Count == 1); Assert.That(actionConfigs[0].ActionType == ItemActionType.ToggleLight); Assert.That(actionConfigs[0].Enabled); // grant an extra item action, before pickup, initially disabled itemActions.GrantOrUpdate(ItemActionType.DebugToggle, false); serverPlayerEnt.GetComponent <HandsComponent>().PutInHand(serverFlashlight.GetComponent <ItemComponent>(), false); // grant an extra item action, after pickup, with a cooldown itemActions.GrantOrUpdate(ItemActionType.DebugInstant, cooldown: cooldown); Assert.That(serverActionsComponent.TryGetItemActionStates(serverFlashlight.Uid, out var state)); // they should have been granted all 3 actions Assert.That(state.Count == 3); Assert.That(state.TryGetValue(ItemActionType.ToggleLight, out var toggleLightState)); Assert.That(toggleLightState.Equals(new ActionState(true))); Assert.That(state.TryGetValue(ItemActionType.DebugInstant, out var debugInstantState)); Assert.That(debugInstantState.Equals(new ActionState(true, cooldown: cooldown))); Assert.That(state.TryGetValue(ItemActionType.DebugToggle, out var debugToggleState)); Assert.That(debugToggleState.Equals(new ActionState(false))); }); await server.WaitRunTicks(5); await client.WaitRunTicks(5); // check that client has the actions, and toggle the light on via the action slot it was auto-assigned to var clientPlayerMgr = client.ResolveDependency <IPlayerManager>(); var clientUIMgr = client.ResolveDependency <IUserInterfaceManager>(); var clientEntMgr = client.ResolveDependency <IEntityManager>(); EntityUid clientFlashlight = default; await client.WaitAssertion(() => { var local = clientPlayerMgr.LocalPlayer; var controlled = local.ControlledEntity; clientActionsComponent = controlled.GetComponent <ClientActionsComponent>(); var lightEntry = clientActionsComponent.ItemActionStates() .Where(entry => entry.Value.ContainsKey(ItemActionType.ToggleLight)) .FirstOrNull(); clientFlashlight = lightEntry.Value.Key; Assert.That(lightEntry, Is.Not.Null); Assert.That(lightEntry.Value.Value.TryGetValue(ItemActionType.ToggleLight, out var lightState)); Assert.That(lightState.Equals(new ActionState(true))); Assert.That(lightEntry.Value.Value.TryGetValue(ItemActionType.DebugInstant, out var debugInstantState)); Assert.That(debugInstantState.Equals(new ActionState(true, cooldown: cooldown))); Assert.That(lightEntry.Value.Value.TryGetValue(ItemActionType.DebugToggle, out var debugToggleState)); Assert.That(debugToggleState.Equals(new ActionState(false))); var actionsUI = clientUIMgr.StateRoot.Children.FirstOrDefault(c => c is ActionsUI) as ActionsUI; Assert.That(actionsUI, Is.Not.Null); var toggleLightSlot = actionsUI.Slots.FirstOrDefault(slot => slot.Action is ItemActionPrototype { ActionType: ItemActionType.ToggleLight }); Assert.That(toggleLightSlot, Is.Not.Null); clientActionsComponent.AttemptAction(toggleLightSlot); });
public async Task PlayerGetIdComponent() { var clientOptions = new ClientIntegrationOptions { ExtraPrototypes = Prototypes }; var serverOptions = new ServerIntegrationOptions { ExtraPrototypes = Prototypes }; var(client, server) = await StartConnectedServerClientPair(clientOptions, serverOptions); await Task.WhenAll(client.WaitIdleAsync(), server.WaitIdleAsync()); var sPlayerManager = server.ResolveDependency <IPlayerManager>(); var sEntityManager = server.ResolveDependency <IEntityManager>(); var invSystem = server.ResolveDependency <IEntitySystemManager>().GetEntitySystem <InventorySystem>(); await server.WaitAssertion(() => { var player = sPlayerManager.Sessions.Single().AttachedEntity.GetValueOrDefault(); Assert.That(player != default); // The player spawns with an ID on by default Assert.NotNull(player.GetHeldId()); Assert.True(player.TryGetHeldId(out var id)); Assert.NotNull(id); // Put PDA in hand var dummyPda = sEntityManager.SpawnEntity(PdaDummy, sEntityManager.GetComponent <TransformComponent>(player).MapPosition); var pdaItemComponent = sEntityManager.GetComponent <SharedItemComponent>(dummyPda); sEntityManager.GetComponent <HandsComponent>(player).PutInHand(pdaItemComponent); var pdaComponent = sEntityManager.GetComponent <PDAComponent>(dummyPda); var pdaIdCard = sEntityManager.SpawnEntity(IdCardDummy, sEntityManager.GetComponent <TransformComponent>(player).MapPosition); var itemSlots = sEntityManager.GetComponent <ItemSlotsComponent>(dummyPda); sEntityManager.EntitySysManager.GetEntitySystem <ItemSlotsSystem>() .TryInsert(dummyPda, pdaComponent.IdSlot, pdaIdCard, null); var pdaContainedId = pdaComponent.ContainedID; // The PDA in the hand should be found first Assert.NotNull(player.GetHeldId()); Assert.True(player.TryGetHeldId(out id)); Assert.NotNull(id); Assert.That(id, Is.EqualTo(pdaContainedId)); // Put ID card in hand var idDummy = sEntityManager.SpawnEntity(IdCardDummy, sEntityManager.GetComponent <TransformComponent>(player).MapPosition); var idItemComponent = sEntityManager.GetComponent <SharedItemComponent>(idDummy); sEntityManager.GetComponent <HandsComponent>(player).PutInHand(idItemComponent); var idCardComponent = sEntityManager.GetComponent <IdCardComponent>(idDummy); // The ID in the hand should be found first Assert.NotNull(player.GetHeldId()); Assert.True(player.TryGetHeldId(out id)); Assert.NotNull(id); Assert.That(id, Is.EqualTo(idCardComponent)); // Remove all IDs and PDAs Assert.That(invSystem.TryGetSlots(player, out var slots)); foreach (var slot in slots) { if (!invSystem.TryGetSlotEntity(player, slot.Name, out var item)) { continue; } if (sEntityManager.HasComponent <PDAComponent>(item)) { invSystem.TryUnequip(player, slot.Name, force: true); } } var hands = sEntityManager.GetComponent <HandsComponent>(player); hands.Drop(dummyPda, false); hands.Drop(idDummy, false); // No ID Assert.Null(player.GetHeldId()); Assert.False(player.TryGetHeldId(out id)); Assert.Null(id); }); }
public async Task BuckleUnbuckleCooldownRangeTest() { var cOptions = new ClientIntegrationOptions { ExtraPrototypes = Prototypes }; var sOptions = new ServerIntegrationOptions { ExtraPrototypes = Prototypes }; var(_, server) = await StartConnectedServerClientPair(cOptions, sOptions); EntityUid human = default; EntityUid chair = default; BuckleComponent buckle = null; StrapComponent strap = null; await server.WaitAssertion(() => { var mapManager = IoCManager.Resolve <IMapManager>(); var entityManager = IoCManager.Resolve <IEntityManager>(); var actionBlocker = EntitySystem.Get <ActionBlockerSystem>(); var standingState = EntitySystem.Get <StandingStateSystem>(); var grid = GetMainGrid(mapManager); var coordinates = new EntityCoordinates(grid.GridEntityId, 0, 0); human = entityManager.SpawnEntity(BuckleDummyId, coordinates); chair = entityManager.SpawnEntity(StrapDummyId, coordinates); // Default state, unbuckled Assert.True(entityManager.TryGetComponent(human, out buckle)); Assert.NotNull(buckle); Assert.Null(buckle.BuckledTo); Assert.False(buckle.Buckled); Assert.True(actionBlocker.CanMove(human)); Assert.True(actionBlocker.CanChangeDirection(human)); Assert.True(standingState.Down(human)); Assert.True(standingState.Stand(human)); // Default state, no buckled entities, strap Assert.True(entityManager.TryGetComponent(chair, out strap)); Assert.NotNull(strap); Assert.IsEmpty(strap.BuckledEntities); Assert.Zero(strap.OccupiedSize); // Side effects of buckling Assert.True(buckle.TryBuckle(human, chair)); Assert.NotNull(buckle.BuckledTo); Assert.True(buckle.Buckled); Assert.True(((BuckleComponentState)buckle.GetComponentState()).Buckled); Assert.False(actionBlocker.CanMove(human)); Assert.False(actionBlocker.CanChangeDirection(human)); Assert.False(standingState.Down(human)); Assert.That((entityManager.GetComponent <TransformComponent>(human).WorldPosition - entityManager.GetComponent <TransformComponent>(chair).WorldPosition).Length, Is.LessThanOrEqualTo(buckle.BuckleOffset.Length)); // Side effects of buckling for the strap Assert.That(strap.BuckledEntities, Does.Contain(human)); Assert.That(strap.OccupiedSize, Is.EqualTo(buckle.Size)); Assert.Positive(strap.OccupiedSize); // Trying to buckle while already buckled fails Assert.False(buckle.TryBuckle(human, chair)); // Trying to unbuckle too quickly fails Assert.False(buckle.TryUnbuckle(human)); Assert.False(buckle.ToggleBuckle(human, chair)); Assert.True(buckle.Buckled); }); // Wait enough ticks for the unbuckling cooldown to run out await server.WaitRunTicks(60); await server.WaitAssertion(() => { var actionBlocker = EntitySystem.Get <ActionBlockerSystem>(); var standingState = EntitySystem.Get <StandingStateSystem>(); // Still buckled Assert.True(buckle.Buckled); // Unbuckle Assert.True(buckle.TryUnbuckle(human)); Assert.Null(buckle.BuckledTo); Assert.False(buckle.Buckled); Assert.True(actionBlocker.CanMove(human)); Assert.True(actionBlocker.CanChangeDirection(human)); Assert.True(standingState.Down(human)); // Unbuckle, strap Assert.IsEmpty(strap.BuckledEntities); Assert.Zero(strap.OccupiedSize); // Re-buckling has no cooldown Assert.True(buckle.TryBuckle(human, chair)); Assert.True(buckle.Buckled); // On cooldown Assert.False(buckle.TryUnbuckle(human)); Assert.True(buckle.Buckled); Assert.False(buckle.ToggleBuckle(human, chair)); Assert.True(buckle.Buckled); Assert.False(buckle.ToggleBuckle(human, chair)); Assert.True(buckle.Buckled); }); // Wait enough ticks for the unbuckling cooldown to run out await server.WaitRunTicks(60); await server.WaitAssertion(() => { var entityManager = IoCManager.Resolve <IEntityManager>(); var actionBlocker = EntitySystem.Get <ActionBlockerSystem>(); var standingState = EntitySystem.Get <StandingStateSystem>(); // Still buckled Assert.True(buckle.Buckled); // Unbuckle Assert.True(buckle.TryUnbuckle(human)); Assert.False(buckle.Buckled); // Move away from the chair entityManager.GetComponent <TransformComponent>(human).WorldPosition += (1000, 1000); // Out of range Assert.False(buckle.TryBuckle(human, chair)); Assert.False(buckle.TryUnbuckle(human)); Assert.False(buckle.ToggleBuckle(human, chair)); // Move near the chair entityManager.GetComponent <TransformComponent>(human).WorldPosition = entityManager.GetComponent <TransformComponent>(chair).WorldPosition + (0.5f, 0); // In range Assert.True(buckle.TryBuckle(human, chair)); Assert.True(buckle.Buckled); Assert.False(buckle.TryUnbuckle(human)); Assert.True(buckle.Buckled); Assert.False(buckle.ToggleBuckle(human, chair)); Assert.True(buckle.Buckled); // Force unbuckle Assert.True(buckle.TryUnbuckle(human, true)); Assert.False(buckle.Buckled); Assert.True(actionBlocker.CanMove(human)); Assert.True(actionBlocker.CanChangeDirection(human)); Assert.True(standingState.Down(human)); // Re-buckle Assert.True(buckle.TryBuckle(human, chair)); // Move away from the chair entityManager.GetComponent <TransformComponent>(human).WorldPosition += (1, 0); }); await server.WaitRunTicks(1); await server.WaitAssertion(() => { // No longer buckled Assert.False(buckle.Buckled); Assert.Null(buckle.BuckledTo); Assert.IsEmpty(strap.BuckledEntities); }); }
/// <summary> /// Start a headless instance of the client and return an object that can be used to control it. /// </summary> protected virtual ClientIntegrationInstance StartClient(ClientIntegrationOptions options = null) { return(new ClientIntegrationInstance(options)); }
public async Task BuckleUnbuckleCooldownRangeTest() { var cOptions = new ClientIntegrationOptions { ExtraPrototypes = Prototypes }; var sOptions = new ServerIntegrationOptions { ExtraPrototypes = Prototypes }; var(client, server) = await StartConnectedServerClientPair(cOptions, sOptions); IEntity human = null; IEntity chair = null; BuckleComponent buckle = null; StrapComponent strap = null; await server.WaitAssertion(() => { var mapManager = IoCManager.Resolve <IMapManager>(); var entityManager = IoCManager.Resolve <IEntityManager>(); var gridId = new GridId(1); var grid = mapManager.GetGrid(gridId); var coordinates = grid.GridEntityId.ToCoordinates(); human = entityManager.SpawnEntity(BuckleDummyId, coordinates); chair = entityManager.SpawnEntity(StrapDummyId, coordinates); // Default state, unbuckled Assert.True(human.TryGetComponent(out buckle)); Assert.NotNull(buckle); Assert.Null(buckle.BuckledTo); Assert.False(buckle.Buckled); Assert.True(ActionBlockerSystem.CanMove(human)); Assert.True(ActionBlockerSystem.CanChangeDirection(human)); Assert.True(EffectBlockerSystem.CanFall(human)); // Default state, no buckled entities, strap Assert.True(chair.TryGetComponent(out strap)); Assert.NotNull(strap); Assert.IsEmpty(strap.BuckledEntities); Assert.Zero(strap.OccupiedSize); // Side effects of buckling Assert.True(buckle.TryBuckle(human, chair)); Assert.NotNull(buckle.BuckledTo); Assert.True(buckle.Buckled); var player = IoCManager.Resolve <IPlayerManager>().GetAllPlayers().Single(); Assert.True(((BuckleComponentState)buckle.GetComponentState(player)).Buckled); Assert.False(ActionBlockerSystem.CanMove(human)); Assert.False(ActionBlockerSystem.CanChangeDirection(human)); Assert.False(EffectBlockerSystem.CanFall(human)); Assert.That(human.Transform.WorldPosition, Is.EqualTo(chair.Transform.WorldPosition)); // Side effects of buckling for the strap Assert.That(strap.BuckledEntities, Does.Contain(human)); Assert.That(strap.OccupiedSize, Is.EqualTo(buckle.Size)); Assert.Positive(strap.OccupiedSize); // Trying to buckle while already buckled fails Assert.False(buckle.TryBuckle(human, chair)); // Trying to unbuckle too quickly fails Assert.False(buckle.TryUnbuckle(human)); Assert.False(buckle.ToggleBuckle(human, chair)); Assert.True(buckle.Buckled); }); // Wait enough ticks for the unbuckling cooldown to run out await server.WaitRunTicks(60); await server.WaitAssertion(() => { // Still buckled Assert.True(buckle.Buckled); // Unbuckle Assert.True(buckle.TryUnbuckle(human)); Assert.Null(buckle.BuckledTo); Assert.False(buckle.Buckled); Assert.True(ActionBlockerSystem.CanMove(human)); Assert.True(ActionBlockerSystem.CanChangeDirection(human)); Assert.True(EffectBlockerSystem.CanFall(human)); // Unbuckle, strap Assert.IsEmpty(strap.BuckledEntities); Assert.Zero(strap.OccupiedSize); // Re-buckling has no cooldown Assert.True(buckle.TryBuckle(human, chair)); Assert.True(buckle.Buckled); // On cooldown Assert.False(buckle.TryUnbuckle(human)); Assert.True(buckle.Buckled); Assert.False(buckle.ToggleBuckle(human, chair)); Assert.True(buckle.Buckled); Assert.False(buckle.ToggleBuckle(human, chair)); Assert.True(buckle.Buckled); }); // Wait enough ticks for the unbuckling cooldown to run out await server.WaitRunTicks(60); await server.WaitAssertion(() => { // Still buckled Assert.True(buckle.Buckled); // Unbuckle Assert.True(buckle.TryUnbuckle(human)); Assert.False(buckle.Buckled); // Move away from the chair human.Transform.WorldPosition += (1000, 1000); // Out of range Assert.False(buckle.TryBuckle(human, chair)); Assert.False(buckle.TryUnbuckle(human)); Assert.False(buckle.ToggleBuckle(human, chair)); // Move near the chair human.Transform.WorldPosition = chair.Transform.WorldPosition + (0.5f, 0); // In range Assert.True(buckle.TryBuckle(human, chair)); Assert.True(buckle.Buckled); Assert.False(buckle.TryUnbuckle(human)); Assert.True(buckle.Buckled); Assert.False(buckle.ToggleBuckle(human, chair)); Assert.True(buckle.Buckled); // Force unbuckle Assert.True(buckle.TryUnbuckle(human, true)); Assert.False(buckle.Buckled); Assert.True(ActionBlockerSystem.CanMove(human)); Assert.True(ActionBlockerSystem.CanChangeDirection(human)); Assert.True(EffectBlockerSystem.CanFall(human)); // Re-buckle Assert.True(buckle.TryBuckle(human, chair)); // Move away from the chair human.Transform.WorldPosition += (1, 0); }); await server.WaitRunTicks(1); await server.WaitAssertion(() => { // No longer buckled Assert.False(buckle.Buckled); Assert.Null(buckle.BuckledTo); Assert.IsEmpty(strap.BuckledEntities); }); }
public async Task PlayerGetIdComponent() { var clientOptions = new ClientIntegrationOptions { ExtraPrototypes = Prototypes }; var serverOptions = new ServerIntegrationOptions { ExtraPrototypes = Prototypes }; var(client, server) = await StartConnectedServerClientPair(clientOptions, serverOptions); await Task.WhenAll(client.WaitIdleAsync(), server.WaitIdleAsync()); var sPlayerManager = server.ResolveDependency <IPlayerManager>(); var sEntityManager = server.ResolveDependency <IEntityManager>(); await server.WaitAssertion(() => { var player = sPlayerManager.GetAllPlayers().Single().AttachedEntity; Assert.NotNull(player); // The player spawns with an ID on by default Assert.NotNull(player.GetHeldId()); Assert.True(player.TryGetHeldId(out var id)); Assert.NotNull(id); // Put PDA in hand var dummyPda = sEntityManager.SpawnEntity(PdaDummy, player.Transform.MapPosition); var pdaItemComponent = dummyPda.GetComponent <ItemComponent>(); player.GetComponent <IHandsComponent>().PutInHand(pdaItemComponent); var pdaComponent = dummyPda.GetComponent <PDAComponent>(); var pdaIdCard = sEntityManager.SpawnEntity(IdCardDummy, player.Transform.MapPosition).GetComponent <IdCardComponent>(); pdaComponent.InsertIdCard(pdaIdCard); var pdaContainedId = pdaComponent.ContainedID; // The PDA in the hand should be found first Assert.NotNull(player.GetHeldId()); Assert.True(player.TryGetHeldId(out id)); Assert.NotNull(id); Assert.That(id, Is.EqualTo(pdaContainedId)); // Put ID card in hand var idDummy = sEntityManager.SpawnEntity(IdCardDummy, player.Transform.MapPosition); var idItemComponent = idDummy.GetComponent <ItemComponent>(); player.GetComponent <IHandsComponent>().PutInHand(idItemComponent); var idCardComponent = idDummy.GetComponent <IdCardComponent>(); // The ID in the hand should be found first Assert.NotNull(player.GetHeldId()); Assert.True(player.TryGetHeldId(out id)); Assert.NotNull(id); Assert.That(id, Is.EqualTo(idCardComponent)); // Remove all IDs and PDAs var inventory = player.GetComponent <InventoryComponent>(); foreach (var slot in inventory.Slots) { var item = inventory.GetSlotItem(slot); if (item == null) { continue; } if (item.Owner.HasComponent <PDAComponent>()) { inventory.ForceUnequip(slot); } } var hands = player.GetComponent <IHandsComponent>(); hands.Drop(dummyPda, false); hands.Drop(idDummy, false); // No ID Assert.Null(player.GetHeldId()); Assert.False(player.TryGetHeldId(out id)); Assert.Null(id); }); }