Example #1
0
        public Treasure GenerateAtLevel(int level)
        {
            if (level < LevelLimits.Minimum || level > LevelLimits.Maximum)
            {
                throw new ArgumentException($"Level {level} is not a valid level for treasure generation");
            }

            var treasure = new Treasure();

            treasure.Coin  = coinFactory.GenerateAtLevel(level);
            treasure.Goods = goodsFactory.GenerateAtLevel(level);
            treasure.Items = itemsFactory.GenerateRandomAtLevel(level);

            return(treasure);
        }
        private void GenerateAndAssertRandomItems()
        {
            var level = GetNewLevel();
            var items = itemsGenerator.GenerateRandomAtLevel(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);
            }
        }
Example #3
0
        private void UpdateCreatureEquipment(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 = itemsGenerator.GenerateRandomAtLevel(creature.HitPoints.RoundedHitDiceQuantity);
                        items = items.Take(quantity - ghostItems.Count);

                        ghostItems.AddRange(items);
                    }

                    creature.Equipment.Items = creature.Equipment.Items.Union(ghostItems);
                }
            }
        }
 public void GenerateRandomAtLevel_ThrowsException_LevelTooLow()
 {
     Assert.That(() => itemsGenerator.GenerateRandomAtLevel(LevelLimits.Minimum - 1),
                 Throws.ArgumentException.With.Message.EqualTo($"Level 0 is not a valid level for treasure generation"));
 }