public async Task TestGridNoDeletes() { var options = new ServerIntegrationOptions() { CVarOverrides = { { CVars.GameDeleteEmptyGrids.Name, "false" } } }; var server = StartServer(options); await server.WaitIdleAsync(); var entManager = server.ResolveDependency <IEntityManager>(); var mapManager = server.ResolveDependency <IMapManager>(); await server.WaitAssertion(() => { var mapId = mapManager.CreateMap(); var grid = mapManager.CreateGrid(mapId); for (var i = 0; i < 10; i++) { grid.SetTile(new Vector2i(i, 0), new Tile(1)); } for (var i = 10; i >= 0; i--) { grid.SetTile(new Vector2i(i, 0), Tile.Empty); } Assert.That(!((!entManager.EntityExists(grid.GridEntityId) ? EntityLifeStage.Deleted : entManager.GetComponent <MetaDataComponent>(grid.GridEntityId).EntityLifeStage) >= EntityLifeStage.Deleted)); }); }
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); }
public async Task ForceUnbuckleBuckleTest() { var options = new ServerIntegrationOptions { ExtraPrototypes = Prototypes }; var server = StartServer(options); IEntity human = null; IEntity chair = null; BuckleComponent buckle = 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); // Component sanity check Assert.True(human.TryGetComponent(out buckle)); Assert.True(chair.HasComponent <StrapComponent>()); // Buckle Assert.True(buckle.TryBuckle(human, chair)); Assert.NotNull(buckle.BuckledTo); Assert.True(buckle.Buckled); // Move the buckled entity away human.Transform.LocalPosition += (100, 0); }); await WaitUntil(server, () => !buckle.Buckled, 10); Assert.False(buckle.Buckled); await server.WaitAssertion(() => { // Move the now unbuckled entity back onto the chair human.Transform.LocalPosition -= (100, 0); // Buckle Assert.True(buckle.TryBuckle(human, chair)); Assert.NotNull(buckle.BuckledTo); Assert.True(buckle.Buckled); }); await server.WaitRunTicks(60); await server.WaitAssertion(() => { // Still buckled Assert.NotNull(buckle.BuckledTo); Assert.True(buckle.Buckled); }); }
public async Task RejuvenateDeadTest() { var options = new ServerIntegrationOptions { ExtraPrototypes = PROTOTYPES }; var server = StartServerDummyTicker(options); await server.WaitAssertion(() => { var mapManager = IoCManager.Resolve <IMapManager>(); mapManager.CreateNewMapEntity(MapId.Nullspace); var entityManager = IoCManager.Resolve <IEntityManager>(); var human = entityManager.SpawnEntity("DamageableDummy", MapCoordinates.Nullspace); // Sanity check Assert.True(human.TryGetComponent(out IDamageableComponent damageable)); Assert.That(damageable.CurrentState, Is.EqualTo(DamageState.Alive)); // Kill the entity damageable.ChangeDamage(DamageClass.Brute, 10000000, true); // Check that it is dead Assert.That(damageable.CurrentState, Is.EqualTo(DamageState.Dead)); // Rejuvenate them RejuvenateVerb.PerformRejuvenate(human); // Check that it is alive and with no damage Assert.That(damageable.CurrentState, Is.EqualTo(DamageState.Alive)); Assert.That(damageable.TotalDamage, Is.Zero); }); }
public async Task TestCancelled() { Task <DoAfterStatus> task = null; var options = new ServerIntegrationOptions { ExtraPrototypes = Prototypes }; var server = StartServerDummyTicker(options); server.Post(() => { var tickTime = 1.0f / IoCManager.Resolve <IGameTiming>().TickRate; var mapManager = IoCManager.Resolve <IMapManager>(); mapManager.CreateNewMapEntity(MapId.Nullspace); var entityManager = IoCManager.Resolve <IEntityManager>(); var mob = entityManager.SpawnEntity("Dummy", MapCoordinates.Nullspace); var cancelToken = new CancellationTokenSource(); var args = new DoAfterEventArgs(mob, tickTime * 2, cancelToken.Token); task = EntitySystem.Get <DoAfterSystem>().DoAfter(args); cancelToken.Cancel(); }); await server.WaitRunTicks(3); Assert.That(task.Result == DoAfterStatus.Cancelled, $"Result was {task.Result}"); }
protected override ServerIntegrationInstance StartServer(ServerIntegrationOptions options = null) { options ??= new ServerIntegrationOptions(); options.ServerContentAssembly = typeof(Server.EntryPoint).Assembly; options.SharedContentAssembly = typeof(Shared.EntryPoint).Assembly; return(base.StartServer(options)); }
public async Task PowerNetTest() { var options = new ServerIntegrationOptions { ExtraPrototypes = Prototypes }; var server = StartServerDummyTicker(options); PowerSupplierComponent supplier = default !;
public async Task Test() { var options = new ServerIntegrationOptions { ExtraPrototypes = Prototypes }; var server = StartServerDummyTicker(options); await server.WaitIdleAsync(); IEntity human = default !;
internal ServerIntegrationInstance(ServerIntegrationOptions options) { _options = options; InstanceThread = new Thread(_serverMain) { Name = "Server Instance Thread" }; DependencyCollection = new DependencyCollection(); InstanceThread.Start(); }
public async Task Test() { var options = new ServerIntegrationOptions { ExtraPrototypes = Prototypes }; var server = StartServer(options); EntityUid human; EntityUid otherHuman; EntityUid cuffs; EntityUid secondCuffs; CuffableComponent cuffed; HandsComponent hands; server.Assert(() => { var mapManager = IoCManager.Resolve <IMapManager>(); var mapId = mapManager.CreateMap(); var coordinates = new MapCoordinates(Vector2.Zero, mapId); var entityManager = IoCManager.Resolve <IEntityManager>(); // Spawn the entities human = entityManager.SpawnEntity("HumanDummy", coordinates); otherHuman = entityManager.SpawnEntity("HumanDummy", coordinates); cuffs = entityManager.SpawnEntity("HandcuffsDummy", coordinates); secondCuffs = entityManager.SpawnEntity("HandcuffsDummy", coordinates); entityManager.GetComponent <TransformComponent>(human).WorldPosition = entityManager.GetComponent <TransformComponent>(otherHuman).WorldPosition; // Test for components existing Assert.True(entityManager.TryGetComponent(human, out cuffed), $"Human has no {nameof(CuffableComponent)}"); Assert.True(entityManager.TryGetComponent(human, out hands), $"Human has no {nameof(HandsComponent)}"); Assert.True(entityManager.TryGetComponent(human, out SharedBodyComponent? _), $"Human has no {nameof(SharedBodyComponent)}"); Assert.True(entityManager.TryGetComponent(cuffs, out HandcuffComponent? _), $"Handcuff has no {nameof(HandcuffComponent)}"); Assert.True(entityManager.TryGetComponent(secondCuffs, out HandcuffComponent? _), $"Second handcuffs has no {nameof(HandcuffComponent)}"); // Test to ensure cuffed players register the handcuffs cuffed.TryAddNewCuffs(human, cuffs); Assert.True(cuffed.CuffedHandCount > 0, "Handcuffing a player did not result in their hands being cuffed"); // Test to ensure a player with 4 hands will still only have 2 hands cuffed AddHand(cuffed.Owner); AddHand(cuffed.Owner); Assert.That(cuffed.CuffedHandCount, Is.EqualTo(2)); Assert.That(hands.SortedHands.Count(), Is.EqualTo(4)); // Test to give a player with 4 hands 2 sets of cuffs cuffed.TryAddNewCuffs(human, secondCuffs); Assert.True(cuffed.CuffedHandCount == 4, "Player doesn't have correct amount of hands cuffed"); }); await server.WaitIdleAsync(); }
public async Task Test() { var options = new ServerIntegrationOptions { ExtraPrototypes = PROTOTYPES }; var server = StartServerDummyTicker(options); IEntity human; IEntity otherHuman; IEntity cuffs; IEntity secondCuffs; HandcuffComponent handcuff; HandcuffComponent secondHandcuff; CuffableComponent cuffed; IHandsComponent hands; IBody body; server.Assert(() => { var mapManager = IoCManager.Resolve <IMapManager>(); mapManager.CreateNewMapEntity(MapId.Nullspace); var entityManager = IoCManager.Resolve <IEntityManager>(); // Spawn the entities human = entityManager.SpawnEntity("HumanDummy", MapCoordinates.Nullspace); otherHuman = entityManager.SpawnEntity("HumanDummy", MapCoordinates.Nullspace); cuffs = entityManager.SpawnEntity("HandcuffsDummy", MapCoordinates.Nullspace); secondCuffs = entityManager.SpawnEntity("HandcuffsDummy", MapCoordinates.Nullspace); human.Transform.WorldPosition = otherHuman.Transform.WorldPosition; // Test for components existing Assert.True(human.TryGetComponent(out cuffed !), $"Human has no {nameof(CuffableComponent)}"); Assert.True(human.TryGetComponent(out hands !), $"Human has no {nameof(HandsComponent)}"); Assert.True(human.TryGetComponent(out body !), $"Human has no {nameof(IBody)}"); Assert.True(cuffs.TryGetComponent(out handcuff !), $"Handcuff has no {nameof(HandcuffComponent)}"); Assert.True(secondCuffs.TryGetComponent(out secondHandcuff !), $"Second handcuffs has no {nameof(HandcuffComponent)}"); // Test to ensure cuffed players register the handcuffs cuffed.AddNewCuffs(cuffs); Assert.True(cuffed.CuffedHandCount > 0, "Handcuffing a player did not result in their hands being cuffed"); // Test to ensure a player with 4 hands will still only have 2 hands cuffed AddHand(cuffed.Owner); AddHand(cuffed.Owner); Assert.True(cuffed.CuffedHandCount == 2 && hands.Hands.Count() == 4, "Player doesn't have correct amount of hands cuffed"); // Test to give a player with 4 hands 2 sets of cuffs cuffed.AddNewCuffs(secondCuffs); Assert.True(cuffed.CuffedHandCount == 4, "Player doesn't have correct amount of hands cuffed"); }); await server.WaitIdleAsync(); }
public async Task Test() { var options = new ServerIntegrationOptions { ExtraPrototypes = PROTOTYPES }; var server = StartServerDummyTicker(options); await server.WaitIdleAsync(); var entityManager = server.ResolveDependency <IEntityManager>(); var tileLookup = server.ResolveDependency <IEntitySystemManager>().GetEntitySystem <GridTileLookupSystem>(); var mapManager = server.ResolveDependency <IMapManager>(); var tileDefinitionManager = server.ResolveDependency <ITileDefinitionManager>(); server.Assert(() => { List <IEntity> entities; var mapOne = mapManager.CreateMap(); var gridOne = mapManager.CreateGrid(mapOne); var tileDefinition = tileDefinitionManager["underplating"]; var underplating = new Tile(tileDefinition.TileId); gridOne.SetTile(new Vector2i(0, 0), underplating); gridOne.SetTile(new Vector2i(-1, -1), underplating); entities = tileLookup.GetEntitiesIntersecting(gridOne.Index, new Vector2i(0, 0)).ToList(); Assert.That(entities.Count, Is.EqualTo(0)); // Space entity, check that nothing intersects it and that also it doesn't throw. entityManager.SpawnEntity("Dummy", new MapCoordinates(Vector2.One * 1000, mapOne)); entities = tileLookup.GetEntitiesIntersecting(gridOne.Index, new Vector2i(1000, 1000)).ToList(); Assert.That(entities.Count, Is.EqualTo(0)); var entityOne = entityManager.SpawnEntity("Dummy", new EntityCoordinates(gridOne.GridEntityId, Vector2.Zero)); entityManager.SpawnEntity("Dummy", new EntityCoordinates(gridOne.GridEntityId, Vector2.One)); var entityTiles = tileLookup.GetIndices(entityOne); Assert.That(entityTiles.Count, Is.EqualTo(2)); entities = tileLookup.GetEntitiesIntersecting(entityOne).ToList(); // Includes station entity Assert.That(entities.Count, Is.EqualTo(3)); // Both dummies should be in each corner of the 0,0 tile but only one dummy intersects -1,-1 entities = tileLookup.GetEntitiesIntersecting(gridOne.Index, new Vector2i(-1, -1)).ToList(); Assert.That(entities.Count, Is.EqualTo(1)); entities = tileLookup.GetEntitiesIntersecting(gridOne.Index, new Vector2i(0, 0)).ToList(); Assert.That(entities.Count, Is.EqualTo(2)); }); await server.WaitIdleAsync(); }
public async Task Test() { var options = new ServerIntegrationOptions { ExtraPrototypes = Prototypes }; var server = StartServer(options); EntityUid human = default; EntityUid uniform = default; EntityUid idCard = default; EntityUid pocketItem = default; InventorySystem invSystem = default !;
public async Task PowerNetTest() { var options = new ServerIntegrationOptions { ExtraPrototypes = Prototypes }; var server = StartServerDummyTicker(options); PowerSupplierComponent supplier = null; PowerConsumerComponent consumer1 = null; PowerConsumerComponent consumer2 = null; server.Assert(() => { var mapMan = IoCManager.Resolve <IMapManager>(); var entityMan = IoCManager.Resolve <IEntityManager>(); mapMan.CreateMap(new MapId(1)); var grid = mapMan.CreateGrid(new MapId(1)); var generatorEnt = entityMan.SpawnEntity("GeneratorDummy", grid.ToCoordinates()); var consumerEnt1 = entityMan.SpawnEntity("ConsumerDummy", grid.ToCoordinates(0, 1)); var consumerEnt2 = entityMan.SpawnEntity("ConsumerDummy", grid.ToCoordinates(0, 2)); if (generatorEnt.TryGetComponent(out AnchorableComponent anchorable)) { anchorable.TryAnchor(null, force: true); } Assert.That(generatorEnt.TryGetComponent(out supplier)); Assert.That(consumerEnt1.TryGetComponent(out consumer1)); Assert.That(consumerEnt2.TryGetComponent(out consumer2)); var supplyRate = 1000; //arbitrary amount of power supply supplier.SupplyRate = supplyRate; consumer1.DrawRate = supplyRate / 2; //arbitrary draw less than supply consumer2.DrawRate = supplyRate * 2; //arbitrary draw greater than supply consumer1.Priority = Priority.First; //power goes to this consumer first consumer2.Priority = Priority.Last; //any excess power should go to low priority consumer }); server.RunTicks(1); //let run a tick for PowerNet to process power server.Assert(() => { Assert.That(consumer1.DrawRate, Is.EqualTo(consumer1.ReceivedPower)); //first should be fully powered Assert.That(consumer2.ReceivedPower, Is.EqualTo(supplier.SupplyRate - consumer1.ReceivedPower)); //second should get remaining power }); await server.WaitIdleAsync(); }
public async Task SpawnItemInSlotTest() { var options = new ServerIntegrationOptions { ExtraPrototypes = Prototypes }; var server = StartServer(options); await server.WaitIdleAsync(); var sEntities = server.ResolveDependency <IEntityManager>(); EntityUid human = default; InventoryComponent inventory = null; await server.WaitAssertion(() => { var mapMan = IoCManager.Resolve <IMapManager>(); mapMan.CreateNewMapEntity(MapId.Nullspace); human = sEntities.SpawnEntity("InventoryStunnableDummy", MapCoordinates.Nullspace); inventory = sEntities.GetComponent <InventoryComponent>(human); // Can't do the test if this human doesn't have the slots for it. Assert.That(inventory.HasSlot(Slots.INNERCLOTHING)); Assert.That(inventory.HasSlot(Slots.IDCARD)); Assert.That(inventory.SpawnItemInSlot(Slots.INNERCLOTHING, "InventoryJumpsuitJanitorDummy", true)); // Do we actually have the uniform equipped? Assert.That(inventory.TryGetSlotItem(Slots.INNERCLOTHING, out ItemComponent uniform)); Assert.That(sEntities.GetComponent <MetaDataComponent>(uniform.Owner).EntityPrototype is { ID: "InventoryJumpsuitJanitorDummy" }); EntitySystem.Get <StunSystem>().TryStun(human, TimeSpan.FromSeconds(1f), true); // Since the mob is stunned, they can't equip this. Assert.That(inventory.SpawnItemInSlot(Slots.IDCARD, "InventoryIDCardDummy", true), Is.False); // Make sure we don't have the ID card equipped. Assert.That(inventory.TryGetSlotItem(Slots.IDCARD, out ItemComponent _), Is.False); // Let's try skipping the interaction check and see if it equips it! Assert.That(inventory.SpawnItemInSlot(Slots.IDCARD, "InventoryIDCardDummy")); Assert.That(inventory.TryGetSlotItem(Slots.IDCARD, out ItemComponent id)); Assert.That(sEntities.GetComponent <MetaDataComponent>(id.Owner).EntityPrototype is { ID: "InventoryIDCardDummy" });
public async Task TestCollisionWakeGrid() { var options = new ServerIntegrationOptions { ExtraPrototypes = Prototype }; options.CVarOverrides["physics.timetosleep"] = "0.0"; var server = StartServer(options); await server.WaitIdleAsync(); var entManager = server.ResolveDependency <IEntityManager>(); var mapManager = server.ResolveDependency <IMapManager>(); IMapGrid grid = default !;
public async Task Setup() { var options = new ServerIntegrationOptions { ExtraPrototypes = Prototypes }; _server = StartServerDummyTicker(options); await _server.WaitIdleAsync(); _mapManager = _server.ResolveDependency <IMapManager>(); _entityManager = _server.ResolveDependency <IEntityManager>(); _gameTiming = _server.ResolveDependency <IGameTiming>(); }
public async Task SpawnItemInSlotTest() { var options = new ServerIntegrationOptions { ExtraPrototypes = PROTOTYPES }; var server = StartServerDummyTicker(options); IEntity human = null; InventoryComponent inventory = null; StunnableComponent stun = null; server.Assert(() => { var mapMan = IoCManager.Resolve <IMapManager>(); mapMan.CreateNewMapEntity(MapId.Nullspace); var entityMan = IoCManager.Resolve <IEntityManager>(); human = entityMan.SpawnEntity("InventoryStunnableDummy", MapCoordinates.Nullspace); inventory = human.GetComponent <InventoryComponent>(); stun = human.GetComponent <StunnableComponent>(); // Can't do the test if this human doesn't have the slots for it. Assert.That(inventory.HasSlot(Slots.INNERCLOTHING)); Assert.That(inventory.HasSlot(Slots.IDCARD)); Assert.That(inventory.SpawnItemInSlot(Slots.INNERCLOTHING, "ClothingUniformJumpsuitJanitor", true)); // Do we actually have the uniform equipped? Assert.That(inventory.TryGetSlotItem(Slots.INNERCLOTHING, out ItemComponent uniform)); Assert.That(uniform.Owner.Prototype != null && uniform.Owner.Prototype.ID == "ClothingUniformJumpsuitJanitor"); stun.Stun(1f); // Since the mob is stunned, they can't equip this. Assert.That(inventory.SpawnItemInSlot(Slots.IDCARD, "AssistantIDCard", true), Is.False); // Make sure we don't have the ID card equipped. Assert.That(inventory.TryGetSlotItem(Slots.IDCARD, out ItemComponent _), Is.False); // Let's try skipping the interaction check and see if it equips it! Assert.That(inventory.SpawnItemInSlot(Slots.IDCARD, "AssistantIDCard", false)); Assert.That(inventory.TryGetSlotItem(Slots.IDCARD, out ItemComponent id)); Assert.That(id.Owner.Prototype != null && id.Owner.Prototype.ID == "AssistantIDCard"); }); await server.WaitIdleAsync(); }
public async Task RejuvenateDeadTest() { var options = new ServerIntegrationOptions { ExtraPrototypes = Prototypes }; var server = StartServer(options); await server.WaitAssertion(() => { var mapManager = IoCManager.Resolve <IMapManager>(); mapManager.CreateNewMapEntity(MapId.Nullspace); var entityManager = IoCManager.Resolve <IEntityManager>(); var prototypeManager = IoCManager.Resolve <IPrototypeManager>(); var human = entityManager.SpawnEntity("DamageableDummy", MapCoordinates.Nullspace); // Sanity check Assert.True(IoCManager.Resolve <IEntityManager>().TryGetComponent(human, out DamageableComponent damageable)); Assert.True(IoCManager.Resolve <IEntityManager>().TryGetComponent(human, out MobStateComponent mobState)); mobState.UpdateState(0); Assert.That(mobState.IsAlive, Is.True); Assert.That(mobState.IsCritical, Is.False); Assert.That(mobState.IsDead, Is.False); Assert.That(mobState.IsIncapacitated, Is.False); // Kill the entity DamageSpecifier damage = new(prototypeManager.Index <DamageGroupPrototype>("Toxin"), FixedPoint2.New(10000000)); EntitySystem.Get <DamageableSystem>().TryChangeDamage(human, damage, true); // Check that it is dead Assert.That(mobState.IsAlive, Is.False); Assert.That(mobState.IsCritical, Is.False); Assert.That(mobState.IsDead, Is.True); Assert.That(mobState.IsIncapacitated, Is.True); // Rejuvenate them RejuvenateCommand.PerformRejuvenate(human); // Check that it is alive and with no damage Assert.That(mobState.IsAlive, Is.True); Assert.That(mobState.IsCritical, Is.False); Assert.That(mobState.IsDead, Is.False); Assert.That(mobState.IsIncapacitated, Is.False); Assert.That(damageable.TotalDamage, Is.EqualTo(FixedPoint2.Zero)); }); }
public async Task Test() { var options = new ServerIntegrationOptions { ExtraPrototypes = Prototypes }; var server = StartServerDummyTicker(options); IEntity generator = null; IMapGrid grid1 = null; IMapGrid grid2 = null; // Create grids server.Assert(() => { var mapMan = IoCManager.Resolve <IMapManager>(); mapMan.CreateMap(new MapId(1)); grid1 = mapMan.CreateGrid(new MapId(1)); grid2 = mapMan.CreateGrid(new MapId(1)); var entityMan = IoCManager.Resolve <IEntityManager>(); generator = entityMan.SpawnEntity("GravityGeneratorDummy", grid2.ToCoordinates()); Assert.That(generator.HasComponent <GravityGeneratorComponent>()); Assert.That(generator.HasComponent <ApcPowerReceiverComponent>()); var generatorComponent = generator.GetComponent <GravityGeneratorComponent>(); var powerComponent = generator.GetComponent <ApcPowerReceiverComponent>(); Assert.That(generatorComponent.Status, Is.EqualTo(GravityGeneratorStatus.Unpowered)); powerComponent.NeedsPower = false; }); server.RunTicks(1); server.Assert(() => { var generatorComponent = generator.GetComponent <GravityGeneratorComponent>(); Assert.That(generatorComponent.Status, Is.EqualTo(GravityGeneratorStatus.On)); var entityMan = IoCManager.Resolve <IEntityManager>(); var grid1Entity = entityMan.GetEntity(grid1.GridEntityId); var grid2Entity = entityMan.GetEntity(grid2.GridEntityId); Assert.That(!grid1Entity.GetComponent <GravityComponent>().Enabled); Assert.That(grid2Entity.GetComponent <GravityComponent>().Enabled); }); await server.WaitIdleAsync(); }
public async Task Setup() { var options = new ServerIntegrationOptions { ExtraPrototypes = Prototypes }; _server = StartServer(options); await _server.WaitIdleAsync(); _mapManager = _server.ResolveDependency <IMapManager>(); _entityManager = _server.ResolveDependency <IEntityManager>(); _gameTiming = _server.ResolveDependency <IGameTiming>(); _extensionCableSystem = _entityManager.EntitySysManager.GetEntitySystem <ExtensionCableSystem>(); }
public async Task ApcChargingTest() { var options = new ServerIntegrationOptions { ExtraPrototypes = Prototypes }; var server = StartServerDummyTicker(options); BatteryComponent apcBattery = null; PowerSupplierComponent substationSupplier = null; server.Assert(() => { var mapMan = IoCManager.Resolve <IMapManager>(); var entityMan = IoCManager.Resolve <IEntityManager>(); mapMan.CreateMap(new MapId(1)); var grid = mapMan.CreateGrid(new MapId(1)); var generatorEnt = entityMan.SpawnEntity("GeneratorDummy", grid.ToCoordinates()); var substationEnt = entityMan.SpawnEntity("SubstationDummy", grid.ToCoordinates(0, 1)); var apcEnt = entityMan.SpawnEntity("ApcDummy", grid.ToCoordinates(0, 2)); Assert.That(generatorEnt.TryGetComponent <PowerSupplierComponent>(out var generatorSupplier)); Assert.That(substationEnt.TryGetComponent(out substationSupplier)); Assert.That(substationEnt.TryGetComponent <BatteryStorageComponent>(out var substationStorage)); Assert.That(substationEnt.TryGetComponent <BatteryDischargerComponent>(out var substationDischarger)); Assert.That(apcEnt.TryGetComponent(out apcBattery)); Assert.That(apcEnt.TryGetComponent <BatteryStorageComponent>(out var apcStorage)); generatorSupplier.SupplyRate = 1000; //arbitrary nonzero amount of power substationStorage.ActiveDrawRate = 1000; //arbitrary nonzero power draw substationDischarger.ActiveSupplyRate = 500; //arbitirary nonzero power supply less than substation storage draw apcStorage.ActiveDrawRate = 500; //arbitrary nonzero power draw apcBattery.MaxCharge = 100; //abbitrary nonzero amount of charge apcBattery.CurrentCharge = 0; //no charge }); server.RunTicks(5); //let run a few ticks for PowerNets to reevaluate and start charging apc server.Assert(() => { Assert.That(substationSupplier.SupplyRate, Is.Not.EqualTo(0)); //substation should be providing power Assert.That(apcBattery.CurrentCharge, Is.Not.EqualTo(0)); //apc battery should have gained charge }); await server.WaitIdleAsync(); }
protected ServerIntegrationInstance StartServerDummyTicker(ServerIntegrationOptions options = null) { options ??= new ServerIntegrationOptions(); options.BeforeStart += () => { IoCManager.Resolve <IModLoader>().SetModuleBaseCallbacks(new ServerModuleTestingCallbacks { ServerBeforeIoC = () => { IoCManager.Register <IGameTicker, DummyGameTicker>(true); } }); }; return(StartServer(options)); }
public async Task TestBehaviorSets() { var options = new ServerIntegrationOptions(); var server = StartServerDummyTicker(options); await server.WaitIdleAsync(); var protoManager = server.ResolveDependency <IPrototypeManager>(); var reflectionManager = server.ResolveDependency <IReflectionManager>(); Dictionary <string, List <string> > behaviorSets = new(); // Test that all BehaviorSet actions exist. await server.WaitAssertion(() => { foreach (var proto in protoManager.EnumeratePrototypes <BehaviorSetPrototype>()) { behaviorSets[proto.ID] = proto.Actions.ToList(); foreach (var action in proto.Actions) { if (!reflectionManager.TryLooseGetType(action, out var actionType) || !typeof(IAiUtility).IsAssignableFrom(actionType)) { Assert.Fail($"Action {action} is not valid within BehaviorSet {proto.ID}"); } } } }); // Test that all BehaviorSets on NPCs exist. await server.WaitAssertion(() => { foreach (var entity in protoManager.EnumeratePrototypes <EntityPrototype>()) { if (!entity.Components.TryGetValue("UtilityAI", out var npcNode)) { continue; } var sets = npcNode["behaviorSets"]; foreach (var entry in (YamlSequenceNode)sets) { Assert.That(behaviorSets.ContainsKey(entry.ToString()), $"BehaviorSet {entry} in entity {entity.ID} not found"); } } }); }
public async Task RejuvenateDeadTest() { var options = new ServerIntegrationOptions { ExtraPrototypes = Prototypes }; var server = StartServerDummyTicker(options); await server.WaitAssertion(() => { var mapManager = IoCManager.Resolve <IMapManager>(); mapManager.CreateNewMapEntity(MapId.Nullspace); var entityManager = IoCManager.Resolve <IEntityManager>(); var prototypeManager = IoCManager.Resolve <IPrototypeManager>(); var human = entityManager.SpawnEntity("DamageableDummy", MapCoordinates.Nullspace); // Sanity check Assert.True(human.TryGetComponent(out IDamageableComponent damageable)); Assert.True(human.TryGetComponent(out IMobStateComponent mobState)); Assert.That(mobState.IsAlive, Is.True); Assert.That(mobState.IsCritical, Is.False); Assert.That(mobState.IsDead, Is.False); Assert.That(mobState.IsIncapacitated, Is.False); // Kill the entity damageable.TryChangeDamage(prototypeManager.Index <DamageGroupPrototype>("Toxin"), 10000000, true); // Check that it is dead Assert.That(mobState.IsAlive, Is.False); Assert.That(mobState.IsCritical, Is.False); Assert.That(mobState.IsDead, Is.True); Assert.That(mobState.IsIncapacitated, Is.True); // Rejuvenate them RejuvenateVerb.PerformRejuvenate(human); // Check that it is alive and with no damage Assert.That(mobState.IsAlive, Is.True); Assert.That(mobState.IsCritical, Is.False); Assert.That(mobState.IsDead, Is.False); Assert.That(mobState.IsIncapacitated, Is.False); Assert.That(damageable.TotalDamage, Is.Zero); }); }
public async Task ApcNetTest() { var options = new ServerIntegrationOptions { ExtraPrototypes = Prototypes }; var server = StartServerDummyTicker(options); PowerReceiverComponent receiver = null; server.Assert(() => { var mapMan = IoCManager.Resolve <IMapManager>(); var entityMan = IoCManager.Resolve <IEntityManager>(); mapMan.CreateMap(new MapId(1)); var grid = mapMan.CreateGrid(new MapId(1)); var apcEnt = entityMan.SpawnEntity("ApcDummy", grid.ToCoordinates(0, 0)); var apcExtensionEnt = entityMan.SpawnEntity("ApcExtensionCableDummy", grid.ToCoordinates(0, 1)); var powerReceiverEnt = entityMan.SpawnEntity("PowerReceiverDummy", grid.ToCoordinates(0, 2)); Assert.That(apcEnt.TryGetComponent <ApcComponent>(out var apc)); Assert.That(apcExtensionEnt.TryGetComponent <PowerProviderComponent>(out var provider)); Assert.That(powerReceiverEnt.TryGetComponent(out receiver)); Assert.NotNull(apc.Battery); provider.PowerTransferRange = 5; //arbitrary range to reach receiver receiver.PowerReceptionRange = 5; //arbitrary range to reach provider apc.Battery.MaxCharge = 10000; //arbitrary nonzero amount of charge apc.Battery.CurrentCharge = apc.Battery.MaxCharge; //fill battery receiver.Load = 1; //arbitrary small amount of power }); server.RunTicks(1); //let run a tick for ApcNet to process power server.Assert(() => { Assert.That(receiver.Powered); }); await server.WaitIdleAsync(); }
public async Task Test() { var options = new ServerIntegrationOptions { ExtraPrototypes = PROTOTYPES }; var server = StartServerDummyTicker(options); IEntity human; IEntity table; ClimbableComponent climbable; ClimbingComponent climbing; server.Assert(() => { var mapManager = IoCManager.Resolve <IMapManager>(); mapManager.CreateNewMapEntity(MapId.Nullspace); var entityManager = IoCManager.Resolve <IEntityManager>(); // Spawn the entities human = entityManager.SpawnEntity("HumanDummy", MapCoordinates.Nullspace); table = entityManager.SpawnEntity("TableDummy", MapCoordinates.Nullspace); // Test for climb components existing // Players and tables should have these in their prototypes. Assert.That(human.TryGetComponent(out climbing !), "Human has no climbing", Is.True); Assert.That(table.TryGetComponent(out climbable !), "Table has no climbable", Is.True); // Now let's make the player enter a climbing transitioning state. climbing.IsClimbing = true; climbing.TryMoveTo(human.Transform.WorldPosition, table.Transform.WorldPosition); var body = human.GetComponent <IPhysicsComponent>(); Assert.That(body.HasController <ClimbController>(), "Player has no ClimbController", Is.True); // Force the player out of climb state. It should immediately remove the ClimbController. climbing.IsClimbing = false; Assert.That(!body.HasController <ClimbController>(), "Player wrongly has a ClimbController", Is.True); }); await server.WaitIdleAsync(); }
public async Task Test() { var options = new ServerIntegrationOptions { ExtraPrototypes = Prototypes }; var server = StartServer(options); EntityUid human; EntityUid table; ClimbingComponent climbing; server.Assert(() => { var mapManager = IoCManager.Resolve <IMapManager>(); mapManager.CreateNewMapEntity(MapId.Nullspace); var entityManager = IoCManager.Resolve <IEntityManager>(); // Spawn the entities human = entityManager.SpawnEntity("HumanDummy", MapCoordinates.Nullspace); table = entityManager.SpawnEntity("TableDummy", MapCoordinates.Nullspace); // Test for climb components existing // Players and tables should have these in their prototypes. Assert.That(entityManager.TryGetComponent(human, out climbing), "Human has no climbing"); Assert.That(entityManager.TryGetComponent(table, out ClimbableComponent? _), "Table has no climbable"); // Now let's make the player enter a climbing transitioning state. climbing.IsClimbing = true; climbing.TryMoveTo(entityManager.GetComponent <TransformComponent>(human).WorldPosition, entityManager.GetComponent <TransformComponent>(table).WorldPosition); var body = entityManager.GetComponent <IPhysBody>(human); // TODO: Check it's climbing // Force the player out of climb state. It should immediately remove the ClimbController. climbing.IsClimbing = false; }); await server.WaitIdleAsync(); }
public async Task WeightlessStatusTest() { var options = new ServerIntegrationOptions { ExtraPrototypes = PROTOTYPES }; var server = StartServer(options); await server.WaitIdleAsync(); var mapManager = server.ResolveDependency <IMapManager>(); var entityManager = server.ResolveDependency <IEntityManager>(); var pauseManager = server.ResolveDependency <IPauseManager>(); var tileDefinitionManager = server.ResolveDependency <ITileDefinitionManager>(); IEntity human = null; SharedAlertsComponent alerts = null; await server.WaitAssertion(() => { var mapId = mapManager.CreateMap(); pauseManager.AddUninitializedMap(mapId); var gridId = new GridId(1); if (!mapManager.TryGetGrid(gridId, out var grid)) { grid = mapManager.CreateGrid(mapId, gridId); } var tileDefinition = tileDefinitionManager["underplating"]; var tile = new Tile(tileDefinition.TileId); var coordinates = grid.ToCoordinates(); grid.SetTile(coordinates, tile); pauseManager.DoMapInitialize(mapId); human = entityManager.SpawnEntity("HumanDummy", coordinates); Assert.True(human.TryGetComponent(out alerts)); }); // Let WeightlessSystem and GravitySystem tick await server.WaitRunTicks(1); GravityGeneratorComponent gravityGenerator = null; await server.WaitAssertion(() => { // No gravity without a gravity generator Assert.True(alerts.IsShowingAlert(AlertType.Weightless)); gravityGenerator = human.EnsureComponent <GravityGeneratorComponent>(); }); // Let WeightlessSystem and GravitySystem tick await server.WaitRunTicks(1); await server.WaitAssertion(() => { Assert.False(alerts.IsShowingAlert(AlertType.Weightless)); // Disable the gravity generator var args = new BreakageEventArgs { Owner = human }; gravityGenerator.OnBreak(args); }); await server.WaitRunTicks(1); await server.WaitAssertion(() => { Assert.False(alerts.IsShowingAlert(AlertType.Weightless)); }); }
public async Task OpenCloseDestroyTest() { var options = new ServerIntegrationOptions { ExtraPrototypes = Prototypes }; var server = StartServerDummyTicker(options); await server.WaitIdleAsync(); var mapManager = server.ResolveDependency <IMapManager>(); var entityManager = server.ResolveDependency <IEntityManager>(); IEntity airlock = null; ServerDoorComponent doorComponent = null; server.Assert(() => { mapManager.CreateNewMapEntity(MapId.Nullspace); airlock = entityManager.SpawnEntity("AirlockDummy", MapCoordinates.Nullspace); Assert.True(airlock.TryGetComponent(out doorComponent)); Assert.That(doorComponent.State, Is.EqualTo(SharedDoorComponent.DoorState.Closed)); }); await server.WaitIdleAsync(); server.Assert(() => { doorComponent.Open(); Assert.That(doorComponent.State, Is.EqualTo(SharedDoorComponent.DoorState.Opening)); }); await server.WaitIdleAsync(); await WaitUntil(server, () => doorComponent.State == SharedDoorComponent.DoorState.Open); Assert.That(doorComponent.State, Is.EqualTo(SharedDoorComponent.DoorState.Open)); server.Assert(() => { doorComponent.Close(); Assert.That(doorComponent.State, Is.EqualTo(SharedDoorComponent.DoorState.Closing)); }); await WaitUntil(server, () => doorComponent.State == SharedDoorComponent.DoorState.Closed); Assert.That(doorComponent.State, Is.EqualTo(SharedDoorComponent.DoorState.Closed)); server.Assert(() => { Assert.DoesNotThrow(() => { airlock.Delete(); }); }); server.RunTicks(5); await server.WaitIdleAsync(); }