public void Execute(IConsoleShell shell, string argStr, string[] args) { if (args.Length < 1) { shell.WriteLine("Wrong number of args."); return; } var entId = new EntityUid(int.Parse(args[0])); if (!_entities.EntityExists(entId)) { shell.WriteLine($"Unable to find entity with uid {entId}"); return; } if (_entities.HasComponent <NPCComponent>(entId)) { shell.WriteLine("Entity already has an AI component."); return; } var comp = _entities.AddComponent <UtilityNPCComponent>(entId); var npcSystem = IoCManager.Resolve <IEntityManager>().EntitySysManager.GetEntitySystem <NPCSystem>(); for (var i = 1; i < args.Length; i++) { var bSet = args[i]; npcSystem.AddBehaviorSet(comp, bSet, false); } npcSystem.RebuildActions(comp); shell.WriteLine("AI component added."); }
public void AddComponent() { var entity = _componentManager.CreateEntity(); var component = A.Fake <IComponent>(); A.CallTo(() => component.Entity).Returns(entity); // TODO: Possibly simplify add component, since component should contain the id of the entity // TODO: Need to resolve if we force the entity id of the component to match the entity // TODO: Protection against adding the same component twice to two different entities? _componentManager.AddComponent(entity, component); A.CallTo(() => _eventSystem.Send(A <object> ._, A <ComponentAdded> ._)) .MustHaveHappenedOnceExactly(); }
public void ShouldQuerySubsets() { var entityOne = em.Create(); var entityTwo = em.Create(); var entityThree = em.Create(); Span <int> subset = stackalloc int[2]; subset[0] = entityTwo; subset[1] = entityThree; em.AddComponent <SampleComponent>(entityOne); em.AddComponent <SampleComponent>(entityTwo); Span <int> storage = stackalloc int[3]; var result = em.QuerySubset(subset, storage, componentTypes); result.Length.Should().Be(1); result[0].Should().Be(entityTwo); }