private IEntity GiveHelmTestItem(uint entityId)
        {
            var item = new Entity(entityId, "TestHelm", new IEntityComponent[]
            {
                new Equipment()
                {
                    EquipmentSlot = EquipmentSlot.Head
                }
            });

            entityEngine.Get(entityId).Returns(item);

            entity.Get <Inventory>().Contents.Add(item);

            return(item);
        }
Beispiel #2
0
        public void GetEntity_GetsEntity()
        {
            var testEntity = engine.New("Test Entity");

            var result = engine.Get(testEntity.EntityId);

            result.Should().Be(testEntity);
        }
Beispiel #3
0
        public void AddItemDirectlyToInventory(IEntity item, Inventory inventory)
        {
            bool addedToStack = false;

            if (item.Has <Stackable>())
            {
                foreach (var itemId in inventory.Contents)
                {
                    var itemInInventory = entityEngine.Get(itemId);
                    if (itemInInventory.Has <Stackable>() && itemInInventory.Get <Stackable>().StacksWith == item.Get <Stackable>().StacksWith)
                    {
                        itemInInventory.Get <Stackable>().StackSize += item.Get <Stackable>().StackSize;
                        DestroyItem(item);
                        addedToStack = true;
                    }
                }
            }

            if (!addedToStack)
            {
                inventory.Contents.Add(item);
            }
        }
Beispiel #4
0
        private static MenuItem ConvertItemToMenuItem(uint itemId, IEntityEngine entityEngine)
        {
            var item = entityEngine.Get(itemId);

            var itemText = item.Get <Description>().Name;

            if (item.Has <Stackable>())
            {
                itemText += $" (x{item.Get<Stackable>().StackSize})";
            }

            if (item.Has <Consumable>())
            {
                itemText += $" ({item.Get<Consumable>().Uses})";
            }

            return(new MenuItem(itemText, item.EntityId));
        }
        private IEntity GetTestItem(string itemName = null, bool hasPosition = true, bool stackable = false, int stackSize = 1)
        {
            var components = new List <IEntityComponent> {
                new Item()
            };

            if (hasPosition)
            {
                components.Add(new Position());
            }

            if (stackable)
            {
                components.Add(new Stackable {
                    StackSize = stackSize, StacksWith = "TestStack"
                });
            }

            var item = new Entity(entityId++, $"TestItem{entityId}", components.ToArray());

            entityEngine.Get(item.EntityId).Returns(item);

            return(item);
        }