public Task CreateAsync(IStaticObjectGenerationContext generationContext)
        {
            if (generationContext is null)
            {
                throw new ArgumentNullException(nameof(generationContext));
            }

            var sector = generationContext.Sector;

            var exitNodes = sector.Map.Transitions.Keys.Cast <HexNode>().Select(x => x.OffsetCoords).ToArray();

            // Генерация препятсвий, как статических объектов.
            foreach (var region in sector.Map.Regions)
            {
                var regionNodes   = region.Nodes.Cast <HexNode>().ToArray();
                var regionCoords  = regionNodes.Select(x => x.OffsetCoords).Except(exitNodes).ToArray();
                var interiorMetas = _interiorObjectRandomSource.RollInteriorObjects(regionCoords);

                foreach (var interior in interiorMetas)
                {
                    var node = regionNodes.Single(x => x.OffsetCoords == interior.Coords);
                    var resourceDepositData = generationContext.ResourceDepositData;
                    var staticObject        = CreateStaticObject(sector, node, resourceDepositData);

                    sector.StaticObjectManager.Add(staticObject);
                }
            }

            var sectorSubScheme = generationContext.Scheme;

            _chestGenerator.CreateChests(sector, sectorSubScheme, sector.Map.Regions);

            return(Task.CompletedTask);
        }
Example #2
0
        private async Task CreateInternalAsync(IStaticObjectGenerationContext generationContext)
        {
            var sector = generationContext.Sector;

            await Task.Run(() =>
            {
                var exitNodes = sector.Map.Transitions.Keys.Cast <HexNode>().Select(x => x.OffsetCoords).ToArray();

                // Генерация препятсвий, как статических объектов.

                if (!generationContext.ResourceDepositData.Items.Any())
                {
                    return;
                }

                var checkPass = sector.Scheme?.Sid != "globe-node";
                foreach (var region in sector.Map.Regions)
                {
                    var regionNodes   = region.Nodes.Cast <HexNode>().ToArray();
                    var regionCoords  = regionNodes.Select(x => x.OffsetCoords).Except(exitNodes).ToArray();
                    var interiorMetas = _interiorObjectRandomSource.RollInteriorObjects(regionCoords, checkPass);

                    foreach (var interior in interiorMetas)
                    {
                        var node = regionNodes.Single(x => x.OffsetCoords == interior.Coords);
                        var resourceDepositData = generationContext.ResourceDepositData;
                        var staticObject        = CreateStaticObject(sector, node, resourceDepositData);

                        sector.StaticObjectManager.Add(staticObject);
                    }
                }

                var sectorSubScheme = generationContext.Scheme;

                if (sectorSubScheme.TotalChestCount > 0)
                {
                    _chestGenerator.CreateChests(sector, sectorSubScheme, sector.Map.Regions);
                }
            });
        }