Esempio n. 1
0
        private async Task UpdateCreatureEquipmentAsync(Creature creature)
        {
            if (creature.CanUseEquipment)
            {
                if (creature.Equipment.Armor != null ||
                    creature.Equipment.Items.Any() ||
                    creature.Equipment.Shield != null ||
                    creature.Equipment.Weapons.Any())
                {
                    var quantity   = dice.Roll(2).d4().AsSum();
                    var ghostItems = new List <Item>();

                    while (ghostItems.Count < quantity)
                    {
                        var items = await itemsGenerator.GenerateRandomAtLevelAsync(creature.HitPoints.RoundedHitDiceQuantity);

                        items = items.Take(quantity - ghostItems.Count);

                        ghostItems.AddRange(items);
                    }

                    creature.Equipment.Items = creature.Equipment.Items.Union(ghostItems);
                }
            }
        }
Esempio n. 2
0
        public async Task <Treasure> GenerateAtLevelAsync(int level)
        {
            var treasure = new Treasure();

            var coinTask  = Task.Run(() => coinFactory.GenerateAtLevel(level));
            var goodsTask = goodsFactory.GenerateAtLevelAsync(level);
            var itemsTask = itemsFactory.GenerateRandomAtLevelAsync(level);

            await Task.WhenAll(coinTask, goodsTask, itemsTask);

            treasure.Coin  = coinTask.Result;
            treasure.Goods = goodsTask.Result;
            treasure.Items = itemsTask.Result;

            return(treasure);
        }
Esempio n. 3
0
        private async Task GenerateAndAssertRandomItemsAsync()
        {
            var level = GetNewLevel();
            var items = await itemsGenerator.GenerateRandomAtLevelAsync(level);

            Assert.That(items, Is.Not.Null);

            if (level > 20)
            {
                Assert.That(items, Is.Not.Empty, $"Level {level}");
            }

            foreach (var item in items)
            {
                itemVerifier.AssertItem(item);
            }
        }
Esempio n. 4
0
        public async Task GenerateRandomAtLevelAsync_ItemsAreGenerated()
        {
            var items = await itemsGenerator.GenerateRandomAtLevelAsync(1);

            Assert.That(items, Is.Not.Null);
        }