public void SetUp() { SystemContainer = new SystemContainer(); SystemContainer.PositionSystem = Substitute.For <IPositionSystem>(); SystemContainer.EventSystem = Substitute.For <IEventSystem>(); SystemContainer.Random = Substitute.For <IRandom>(); entityEngine = Substitute.For <IEntityEngine>(); entityEngine.New(Arg.Any <string>(), Arg.Any <IEntityComponent[]>()).ReturnsForAnyArgs(callInfo => { var entity = new Entity(0, "entity", callInfo.ArgAt <IEntityComponent[]>(1)); entity.Name = callInfo.ArgAt <string>(0); return(entity); }); entityEngine.Load(Arg.Any <uint>(), Arg.Any <Entity>()).ReturnsForAnyArgs(callInfo => { var entity = callInfo.ArgAt <Entity>(1); return(entity); }); entityEngine.ComponentTypes.ReturnsForAnyArgs(new[] { typeof(Appearance), typeof(Position), typeof(Stairs), typeof(AttackClosestEnemyBehaviour), typeof(Script) }); SystemContainer.EntityEngine = entityEngine; }
public void CreateTextParticle(MapCoordinate location, List <AnimationMovement> movements, string text, Color color) { _entityEngine.New("particle", new TextParticle { Text = text, Color = color }, new Position { MapCoordinate = location }, new Moving { Movements = movements } ); }
private IEntity MakeInstanceOf(IEntity entity) { if (entity.Get <Prototype>().Singleton) { return(entity); } var newComponents = new List <IEntityComponent>(); var startWithItems = new List <StartsWithItem>(); foreach (var component in entity.Components.Where(c => c.GetType() != typeof(Prototype))) { if (component is StartsWithItem) { startWithItems.Add((StartsWithItem)component); } else { var componentType = component.GetType(); IEntityComponent newComponent; if (IsBehaviour(componentType)) { newComponent = (IEntityComponent)Activator.CreateInstance(componentType, new object[] { _systemContainer }); } else { newComponent = (IEntityComponent)Activator.CreateInstance(componentType); } foreach (FieldInfo fieldInfo in componentType.GetFields()) { if (fieldInfo.FieldType == typeof(Counter)) { Counter oldValue = (Counter)fieldInfo.GetValue(component); fieldInfo.SetValue(newComponent, new Counter { Current = oldValue.Current, Max = oldValue.Max }); } else if (fieldInfo.FieldType.IsDefined(typeof(AlwaysCreateNewInstanceAttribute), false)) { var instance = Activator.CreateInstance(fieldInfo.FieldType); fieldInfo.SetValue(newComponent, instance); } else { var oldValue = fieldInfo.GetValue(component); fieldInfo.SetValue(newComponent, oldValue); } } newComponents.Add(newComponent); } } var newEntity = _engine.New(null, newComponents.ToArray()); var inventory = newEntity.Get <Inventory>(); foreach (var startItem in startWithItems) { var item = Get(startItem.Item); _systemContainer.ItemSystem.MoveToInventory(item, inventory); if (startItem.Equipped) { _systemContainer.EquipmentSystem.Equip(newEntity, item); } } _systemContainer.EventSystem.Try(EventSystem.EventType.SpawnEntity, newEntity, null); return(newEntity); }
public void New_AddsEntityToList() { var testEntity = engine.New("Test Entity"); engine.AllEntities.Single().Should().Be(testEntity); }