Exemplo n.º 1
0
        public void IterationSetup()
        {
            var startUp           = new Startup();
            var serviceCollection = new ServiceCollection();

            startUp.RegisterServices(serviceCollection);

            _serviceProvider = serviceCollection.BuildServiceProvider();

            var sectorManager        = _serviceProvider.GetRequiredService <ISectorManager>();
            var playerState          = _serviceProvider.GetRequiredService <ISectorUiState>();
            var schemeService        = _serviceProvider.GetRequiredService <ISchemeService>();
            var humanPlayer          = _serviceProvider.GetRequiredService <HumanPlayer>();
            var actorManager         = _serviceProvider.GetRequiredService <IActorManager>();
            var humanActorTaskSource = _serviceProvider.GetRequiredService <IHumanActorTaskSource>();

            TestSectorSubScheme testSectorSubScheme = new TestSectorSubScheme
            {
                RegularMonsterSids = new[] { "rat" },
                RegionMonsterCount = 0,

                MapGeneratorOptions = new TestSectorRoomMapFactoryOptionsSubScheme
                {
                    RegionCount = 20,
                    RegionSize  = 20,
                },

                IsStart = true,

                ChestDropTableSids    = new[] { "survival", "default" },
                RegionChestCountRatio = 9,
                TotalChestCount       = 0
            };

            var sectorNode = new TestMaterializedSectorNode(testSectorSubScheme);

            humanPlayer.BindSectorNode(sectorNode);

            sectorManager.CreateSectorAsync().Wait();

            var personScheme = schemeService.GetScheme <IPersonScheme>("human-person");

            var playerActorStartNode = sectorManager.CurrentSector.Map.Regions
                                       .SingleOrDefault(x => x.IsStart).Nodes
                                       .First();

            var survivalRandomSource = _serviceProvider.GetRequiredService <ISurvivalRandomSource>();
            var playerActorVm        = BenchHelper.CreateHumanActorVm(humanPlayer,
                                                                      schemeService,
                                                                      survivalRandomSource,
                                                                      personScheme,
                                                                      actorManager,
                                                                      playerActorStartNode);

            //Лучше централизовать переключение текущего актёра только в playerState
            playerState.ActiveActor = playerActorVm;
            humanActorTaskSource.SwitchActiveActor(playerState.ActiveActor.Actor);
        }
Exemplo n.º 2
0
        public async Task CreateSectorAsync(int mapSize)
        {
            var mapFactory = (FuncMapFactory)ServiceProvider.GetRequiredService <IMapFactory>();

            mapFactory.SetFunc(() =>
            {
                ISectorMap map = new SectorGraphMap <HexNode, HexMapNodeDistanceCalculator>();

                MapFiller.FillSquareMap(map, mapSize);

                var mapRegion = new MapRegion(1, map.Nodes.ToArray())
                {
                    IsStart   = true,
                    IsOut     = true,
                    ExitNodes = new[] { map.Nodes.Last() }
                };

                map.Regions.Add(mapRegion);

                return(Task.FromResult(map));
            });

            var sectorManager = ServiceProvider.GetRequiredService <ISectorManager>();
            var humanPlayer   = ServiceProvider.GetRequiredService <HumanPlayer>();

            var sectorSubScheme = new TestSectorSubScheme
            {
                RegularMonsterSids  = new[] { "rat" },
                MapGeneratorOptions = new SquareGenerationOptionsSubScheme
                {
                    Size = mapSize
                }
            };

            var sectorNodeMock = new Mock <ISectorNode>();

            sectorNodeMock.SetupGet(x => x.State).Returns(SectorNodeState.SectorMaterialized);
            sectorNodeMock.SetupGet(x => x.SectorScheme).Returns(sectorSubScheme);
            var sectorNode = sectorNodeMock.Object;

            humanPlayer.BindSectorNode(sectorNode);

            await sectorManager.CreateSectorAsync();
        }
Exemplo n.º 3
0
        public async Task CreateMonsters_AlwaysMaxRarityRolls_MaxHighRarityMonstersAsync()
        {
            var schemeDict = new Dictionary <string, IMonsterScheme>
            {
                { "regular", CreateMonsterScheme("regular") },
                { "rare", CreateMonsterScheme("rare") },
                { "champion", CreateMonsterScheme("champion") }
            };

            var schemeServiceMock = new Mock <ISchemeService>();

            schemeServiceMock.Setup(x => x.GetScheme <IMonsterScheme>(It.IsAny <string>()))
            .Returns <string>(sid => schemeDict[sid]);
            var schemeService = schemeServiceMock.Object;

            var dice             = new LinearDice(3121);
            var randomSourceMock = new Mock <MonsterGeneratorRandomSource>(dice).As <IMonsterGeneratorRandomSource>();

            randomSourceMock.CallBase = true;
            randomSourceMock.Setup(x => x.RollRarity()).Returns(2);
            randomSourceMock.Setup(x => x.RollRegionCount(It.IsAny <int>(), It.IsAny <int>())).Returns(20);
            var randomSource = randomSourceMock.Object;

            var actorList        = new List <IActor>();
            var actorManagerMock = new Mock <IActorManager>();

            actorManagerMock.Setup(x => x.Add(It.IsAny <IActor>())).Callback <IActor>(a => actorList.Add(a));
            actorManagerMock.SetupGet(x => x.Items).Returns(actorList);
            var actorManager = actorManagerMock.Object;

            var propContainerManagerMock = new Mock <IStaticObjectManager>();
            var propContainerManager     = propContainerManagerMock.Object;

            propContainerManagerMock.SetupGet(x => x.Items).Returns(Array.Empty <IStaticObject>());

            var taskSourceMock = new Mock <IActorTaskSource <ISectorTaskSourceContext> >();
            var taskSource     = taskSourceMock.Object;

            var monsterFactory = new MonsterPersonFactory();

            var monsterGenerator = new MonsterGenerator(schemeService,
                                                        monsterFactory,
                                                        randomSource,
                                                        taskSource);

            var map = await SquareMapFactory.CreateAsync(20).ConfigureAwait(false);

            var sectorMock = new Mock <ISector>();

            sectorMock.SetupGet(x => x.ActorManager).Returns(actorManager);
            sectorMock.SetupGet(x => x.StaticObjectManager).Returns(propContainerManager);
            sectorMock.SetupGet(x => x.Map).Returns(map);
            var sector = sectorMock.Object;

            var monsterRegions = new List <MapRegion>
            {
                new MapRegion(1, map.Nodes.ToArray())
            };

            var sectorScheme = new TestSectorSubScheme
            {
                RegularMonsterSids  = new[] { "regular" },
                RareMonsterSids     = new[] { "rare" },
                ChampionMonsterSids = new[] { "champion" }
            };

            // ACT
            monsterGenerator.CreateMonsters(sector,
                                            monsterRegions,
                                            sectorScheme);

            // ASSERT
            var championCount = actorManager.Items.Count(x => ((MonsterPerson)x.Person).Scheme.Sid == "champion");

            championCount.Should().Be(1);

            var rareCount = actorManager.Items.Count(x => ((MonsterPerson)x.Person).Scheme.Sid == "rare");

            rareCount.Should().Be(10);
        }
        public async System.Threading.Tasks.Task CreateMonsters_AlwaysMaxRarityRolls_MaxHighRarityMonstersAsync()
        {
            var schemeDict = new Dictionary <string, IMonsterScheme>
            {
                { "regular", CreateMonsterScheme("regular") },
                { "rare", CreateMonsterScheme("rare") },
                { "champion", CreateMonsterScheme("champion") }
            };

            var schemeServiceMock = new Mock <ISchemeService>();

            schemeServiceMock.Setup(x => x.GetScheme <IMonsterScheme>(It.IsAny <string>()))
            .Returns <string>(sid => schemeDict[sid]);
            var schemeService = schemeServiceMock.Object;

            var dice             = new Dice(3121);
            var randomSourceMock = new Mock <MonsterGeneratorRandomSource>(dice).As <IMonsterGeneratorRandomSource>();

            randomSourceMock.CallBase = true;
            randomSourceMock.Setup(x => x.RollRarity()).Returns(2);
            randomSourceMock.Setup(x => x.RollRegionCount(It.IsAny <int>())).Returns(20);
            var randomSource = randomSourceMock.Object;

            var actorList        = new List <IActor>();
            var actorManagerMock = new Mock <IActorManager>();

            actorManagerMock.Setup(x => x.Add(It.IsAny <IActor>())).Callback <IActor>(a => actorList.Add(a));
            actorManagerMock.SetupGet(x => x.Items).Returns(actorList);
            var actorManager = actorManagerMock.Object;

            var monsterGenerator = new MonsterGenerator(schemeService,
                                                        randomSource,
                                                        actorManager);


            var map = await SquareMapFactory.CreateAsync(20);

            var sectorMock   = new Mock <ISector>();
            var patrolRoutes = new Dictionary <IActor, IPatrolRoute>();

            sectorMock.SetupGet(x => x.PatrolRoutes).Returns(patrolRoutes);
            var sector = sectorMock.Object;

            var monsterRegions = new List <MapRegion> {
                new MapRegion(1, map.Nodes.ToArray())
            };

            var sectorScheme = new TestSectorSubScheme
            {
                RegularMonsterSids  = new[] { "regular" },
                RareMonsterSids     = new[] { "rare" },
                ChampionMonsterSids = new[] { "champion" }
            };

            // ACT
            monsterGenerator.CreateMonsters(sector,
                                            new Mock <IBotPlayer>().Object,
                                            monsterRegions,
                                            sectorScheme);



            // ASSERT
            var championCount = actorManager.Items.Count(x => ((MonsterPerson)x.Person).Scheme.Sid == "champion");

            championCount.Should().Be(1);

            var rareCount = actorManager.Items.Count(x => ((MonsterPerson)x.Person).Scheme.Sid == "rare");

            rareCount.Should().Be(10);
        }