Example #1
0
        public void GenerateCaveWithLakeAndEncounter()
        {
            selectedCave.Contents.Miscellaneous = new[] { ContentsTypeConstants.Lake };

            mockPercentileSelector.Setup(s => s.SelectFrom(TableNameConstants.Lakes)).Returns("laketown/Encounter");

            var encounter = new Encounter();
            mockEncounterGenerator.Setup(g => g.Generate(EnvironmentConstants.Dungeon, 90210, "temperature", EnvironmentConstants.TimesOfDay.Night)).Returns(encounter);

            var cave = caveGenerator.Generate(9266, 90210, "temperature").Single();
            Assert.That(cave, Is.EqualTo(selectedCave));
            Assert.That(cave.Contents.Miscellaneous.First(), Is.EqualTo("laketown"));
            Assert.That(cave.Contents.Miscellaneous.Last(), Is.EqualTo(ContentsTypeConstants.Encounter));
            Assert.That(cave.Contents.Miscellaneous.Count(), Is.EqualTo(2));
            Assert.That(cave.Contents.Encounters.Single(), Is.EqualTo(encounter));
        }
        public Encounter Generate(string environment, int level, string temperature, string timeOfDay, params string[] creatureTypeFilters)
        {
            var filtersAreValid = filterVerifier.FiltersAreValid(environment, level, temperature, timeOfDay, creatureTypeFilters);
            if (!filtersAreValid)
                throw new ImpossibleEncounterException();

            var tableName = string.Format(TableNameConstants.LevelXEncounterLevel, level);
            var encounterLevelAndModifier = typeAndAmountPercentileSelector.SelectFrom(tableName).Single();
            var encounterLevel = Convert.ToInt32(encounterLevelAndModifier.Key);
            var modifier = Convert.ToInt32(encounterLevelAndModifier.Value);
            var creatures = new List<Creature>();

            while (creatures.Any() == false || creatures.Contains(null))
            {
                creatures.Clear();

                var encounterCreaturesAndAmounts = creatureCollectionSelector.SelectFrom(encounterLevel, environment, temperature, timeOfDay);
                var iterations = 0;

                while (!filterVerifier.EncounterIsValid(encounterCreaturesAndAmounts, modifier, creatureTypeFilters) && iterations++ < IterationLimit)
                {
                    tableName = string.Format(TableNameConstants.LevelXEncounterLevel, level);
                    encounterLevelAndModifier = typeAndAmountPercentileSelector.SelectFrom(tableName).Single();
                    encounterLevel = Convert.ToInt32(encounterLevelAndModifier.Key);
                    modifier = Convert.ToInt32(encounterLevelAndModifier.Value);

                    encounterCreaturesAndAmounts = creatureCollectionSelector.SelectFrom(encounterLevel, environment, temperature, timeOfDay);
                }

                if (!filterVerifier.EncounterIsValid(encounterCreaturesAndAmounts, modifier, creatureTypeFilters))
                    throw new Exception($"Failed to generate level {level} creature for [{string.Join(",", creatureTypeFilters)}] in {temperature} {environment} {timeOfDay} after {iterations} iterations");

                foreach (var kvp in encounterCreaturesAndAmounts)
                {
                    var newCreature = GetCreature(kvp.Key, kvp.Value, modifier, level, encounterLevel);
                    creatures.Add(newCreature);
                }
            }

            var encounter = new Encounter();
            encounter.Characters = encounterCharacterGenerator.GenerateFrom(creatures);
            encounter.Creatures = EditCreatureTypes(creatures);

            var leadCreature = encounter.Creatures.First();
            encounter.Treasures = GetTreasures(encounter.Creatures, level);

            return encounter;
        }
Example #3
0
 public void Setup()
 {
     encounter = new Encounter();
 }
        public void Setup()
        {
            mockPercentileSelector = new Mock<IPercentileSelector>();
            mockEncounterGenerator = new Mock<IEncounterGenerator>();
            mockTreasureGenerator = new Mock<ITreasureGenerator>();
            poolGenerator = new DomainPoolGenerator(mockPercentileSelector.Object, mockEncounterGenerator.Object, mockTreasureGenerator.Object);

            selectedPool = string.Empty;
            encounter = new Encounter();
            treasure = new Treasure();

            mockPercentileSelector.Setup(s => s.SelectFrom(TableNameConstants.Pools)).Returns(() => selectedPool);
            mockEncounterGenerator.Setup(g => g.Generate(EnvironmentConstants.Dungeon, 9266, "temperature", EnvironmentConstants.TimesOfDay.Night)).Returns(encounter);
            mockTreasureGenerator.Setup(g => g.GenerateAtLevel(9266)).Returns(treasure);
        }
 private bool DragonOccured(Encounter encounter)
 {
     return encounter.Creatures.First().Name.Contains("dragon");
 }
 private bool CharacterOccurred(Encounter encounter)
 {
     return encounter.Characters.Any();
 }
        private void AssertEncounter(Encounter encounter)
        {
            Assert.That(encounter.Creatures, Is.Not.Empty);
            Assert.That(encounter.Creatures, Is.All.Not.Null);
            Assert.That(encounter.Characters, Is.Not.Null);
            Assert.That(encounter.Characters, Is.All.Not.Null);

            foreach (var creature in encounter.Creatures)
            {
                Assert.That(creature.Name, Is.Not.Empty);
                Assert.That(creature.Quantity, Is.Positive);
                Assert.That(creature.Description, Is.Not.Null);
            }

            Assert.That(encounter.Treasures, Is.Not.Null);
            Assert.That(encounter.Treasures, Is.All.Not.Null);
            Assert.That(encounter.Treasures.Select(t => t.IsAny), Is.All.True);

            var totalCreatures = encounter.Creatures.Sum(c => c.Quantity);
            Assert.That(encounter.Characters.Count, Is.LessThanOrEqualTo(totalCreatures));
            Assert.That(encounter.Treasures.Count, Is.LessThanOrEqualTo(encounter.Creatures.Count()));
        }