Exemple #1
0
        public FighterGrouping GetGrouping(FighterGroupingConfiguration config)
        {
            FighterGrouping generatedGrouping = null;

            ShadeGroupingConfiguration shadeConfig = config as ShadeGroupingConfiguration;

            if (shadeConfig != null)
            {
                List <Shade> generatedFighters = new List <Shade>();
                int          minLevel          = shadeConfig.MinLevel;

                for (int i = 0; i < shadeConfig.NumberOfShades; ++i)
                {
                    int level = shadeConfig.MaxLevel == null ?
                                minLevel :
                                _chanceService.WhichEventOccurs(shadeConfig.MaxLevel.Value - minLevel) + minLevel;

                    Shade generatedShade = FighterFactory.GetShade(level);
                    generatedFighters.Add(generatedShade);
                }

                generatedGrouping = new ShadeFighterGrouping(_chanceService, generatedFighters.ToArray());
            }

            return(generatedGrouping);
        }
        public void CorrectlyGeneratesBattlefield_ShadeGroupingAndBellTerrainConfiguration()
        {
            const int fighterLevel = 1;
            FighterGroupingConfiguration groupingConfig = new ShadeGroupingConfiguration(3, fighterLevel);

            BellType[] bellTypes = { BellType.Copper, BellType.Silver };
            TerrainInteractablesConfiguration terrainConfiguration = new BellTerrainConfiguration(bellTypes);

            BattlefieldConfiguration config = new BattlefieldConfiguration(groupingConfig, terrainConfiguration);

            BattleFieldInfo returnedBattleFieldInfo = _factory.GetBattleFieldSetUp(config);

            List <IFighter> fighters = returnedBattleFieldInfo.EnemyTeam.Fighters;

            Assert.AreEqual(3, fighters.Count);
            Assert.True(fighters.TrueForAll(f => f is Shade), "the returned fighters should be Shades!");
            Assert.True(fighters.TrueForAll(f => f.Level == fighterLevel), $"the returned fighters should all be level {fighterLevel}!");

            List <TerrainInteractable> terrainInteractables = returnedBattleFieldInfo.TerrainInteractables.ToList();

            Assert.AreEqual(2, terrainInteractables.Count);
            Assert.True(terrainInteractables.TrueForAll(b => b is Bell));

            List <Bell> bells = terrainInteractables.OfType <Bell>().ToList();

            for (var i = 0; i < bellTypes.Length; ++i)
            {
                Assert.AreEqual(bellTypes[i], bells[i].BellType);
            }
        }
        public void CorrectlyGeneratesEnemyTeams_FromBattlefieldConfiguration([Values(new[] { FighterType.Goblin, FighterType.Fairy }, new[] { FighterType.Warrior, FighterType.ShieldGuy })] IEnumerable <FighterType> enemyTypes)
        {
            List <FighterType> enemyTypesList = enemyTypes.ToList();

            TeamConfiguration bossConfiguration = new TeamConfiguration(new EnemyConfiguration(FighterType.Barbarian, 5), new EnemyConfiguration(FighterType.ShieldGuy, 2), new EnemyConfiguration(FighterType.ShieldGuy, 3));

            ShadeGroupingConfiguration shadeGroupingConfig = new ShadeGroupingConfiguration(3, 1);

            BellType[] bellTypes = { BellType.Silver, BellType.Copper };
            BellTerrainConfiguration bellConfig   = new BellTerrainConfiguration(bellTypes);
            BattlefieldConfiguration battleConfig = new BattlefieldConfiguration(shadeGroupingConfig, bellConfig);

            List <ScriptedBattlefieldConfiguration> scriptedBattlefieldConfigurations = new List
                                                                                        <ScriptedBattlefieldConfiguration>
            {
                new ScriptedBattlefieldConfiguration(battleConfig, 0)
            };

            SubRegion subRegion = new SubRegion(WorldSubRegion.Fields,
                                                1,
                                                new[] { new ChanceEvent <int>(2, 1) },
                                                enemyTypesList,
                                                new BattlefieldConfiguration(bossConfiguration),
                                                scriptedBattlefieldConfigurations);

            SubRegion[] subRegions = { subRegion };

            Region fakeFieldsRegion = new Region(WorldRegion.Fields, new BattleMove[0], subRegions);

            _regionFactory.SetRegion(WorldRegion.Fields, fakeFieldsRegion);

            _regionManager = GetRegionManager();

            _humanFighter1.SetMove(_runawayMove);
            _humanFighter1.SetMoveTarget(_humanFighter1);

            _humanFighter2.SetMove(_doNothingMove);

            _regionManager.Battle(_battleManager, _humanTeam);

            Team            enemyTeam     = _battleManager.GetAllEnemyTeams()[0];
            List <IFighter> enemyFighters = enemyTeam.Fighters;

            Assert.AreEqual(3, enemyFighters.Count);
            Assert.True(enemyFighters.TrueForAll(ef => ef is Shade));

            List <TerrainInteractable> terrainInteractables = _battleManager.GetAllTerrainInteractableLists()[0];

            Assert.NotNull(terrainInteractables);
            Assert.AreEqual(2, terrainInteractables.Count);

            List <Bell> bells = terrainInteractables.OfType <Bell>().ToList();

            Assert.AreEqual(bellTypes.Length, bells.Count);
            for (var i = 0; i < bellTypes.Length; ++i)
            {
                Assert.AreEqual(bellTypes[i], bells[i].BellType);
            }
        }
        public void GetGroupingCorrectlyReturnsShadeGrouping_NoMaxLevel([Range(1, 4)] int numberEnemies, [Range(1, 3)] int fighterLevel)
        {
            ShadeGroupingConfiguration config   = new ShadeGroupingConfiguration(numberEnemies, fighterLevel);
            ShadeFighterGrouping       grouping = _factory.GetGrouping(config) as ShadeFighterGrouping;

            Assert.NotNull(grouping);
            List <Shade> shades = grouping.GetShades();

            Assert.AreEqual(numberEnemies, shades.Count, $"There should be {numberEnemies} shades in the returned grouping");
            Assert.True(shades.TrueForAll(s => s.Level == fighterLevel));
        }
        public void GetGroupingCorrectlyReturnsShadeGrouping_LevelRange([Range(1, 3)] int minLevel, [Range(1, 3)] int levelDiff)
        {
            //Arrange
            int maxLevel       = minLevel + levelDiff;
            int numberFighters = levelDiff + 1;
            ShadeGroupingConfiguration config = new ShadeGroupingConfiguration(numberFighters, minLevel, maxLevel);

            for (int i = 0; i < numberFighters; ++i)
            {
                _chanceService.PushWhichEventOccurs(i);
            }

            //Act
            ShadeFighterGrouping grouping = _factory.GetGrouping(config) as ShadeFighterGrouping;

            //Assert
            Assert.NotNull(grouping);
            List <Shade> shades = grouping.GetShades();

            for (int i = 0; i < numberFighters; ++i)
            {
                Assert.AreEqual(minLevel + i, shades[i].Level);
            }
        }