/// <summary>
        /// Создание
        /// </summary>
        /// <param name="globe">Объект игрового мира, для которого создаётся локация.</param>
        /// <param name="cell">Провинция игрового мира из указанного выше <see cref="Globe" />,
        /// для которого создаётся локация.</param>
        /// <returns>
        /// Возвращает граф локация для провинции.
        /// </returns>
        public Task <GlobeRegion> GenerateRegionAsync(Globe globe, TerrainCell cell)
        {
            var locationSchemeSids = new[] {
                "rat-hole",
                "rat-kingdom",
                "demon-dungeon",
                "demon-lair",
                "crypt",
                "elder-place",
                "genomass-cave"
            };
            var region = new GlobeRegion(LocationBaseSize);

            for (var x = 0; x < LocationBaseSize; x++)
            {
                for (var y = 0; y < LocationBaseSize; y++)
                {
                    //var hasNodeRoll = _dice.Roll(6);
                    //if (hasNodeRoll <= 2)
                    //{
                    //    continue;
                    //}

                    var hasDundeonRoll = _dice.Roll(100);
                    if (hasDundeonRoll > 90)
                    {
                        var locationSidIndex = _dice.Roll(0, locationSchemeSids.Length - 1);
                        var locationSid      = locationSchemeSids[locationSidIndex];
                        var locationScheme   = _schemeService.GetScheme <ILocationScheme>(locationSid);
                        var node             = new GlobeRegionNode(x, y, locationScheme);
                        region.AddNode(node);
                    }
                    else
                    {
                        var hasCityRoll = _dice.Roll(100);

                        if (hasCityRoll > 90)
                        {
                            var locationScheme = _schemeService.GetScheme <ILocationScheme>("city");
                            var node           = new GlobeRegionNode(x, y, locationScheme)
                            {
                                IsTown = true
                            };
                            region.AddNode(node);
                        }
                        else
                        {
                            var locationScheme = _schemeService.GetScheme <ILocationScheme>("forest");
                            var node           = new GlobeRegionNode(x, y, locationScheme);
                            region.AddNode(node);
                        }
                    }
                }
            }

            return(Task.FromResult(region));
        }
Exemplo n.º 2
0
        private void AddNodeIfBorder(GlobeRegion region, int x, int y)
        {
            var locationScheme = _schemeService.GetScheme <ILocationScheme>(WILD_SCHEME_SID);
            var borderNode     = new GlobeRegionNode(x, y, locationScheme)
            {
                IsBorder = true
            };

            region.AddNode(borderNode);
        }
 private static void FillRegion(int regionSize, ILocationScheme regionScheme, GlobeRegion currentRegion)
 {
     for (var x = 0; x < regionSize; x++)
     {
         for (var y = 0; y < regionSize; y++)
         {
             currentRegion.AddNode(new GlobeRegionNode(x, y, regionScheme)
             {
                 IsBorder = x == 0 || x == regionSize - 1 || y == 0 || y == regionSize - 1
             });
         }
     }
 }
Exemplo n.º 4
0
        public GlobeRegion Restore(ISchemeService schemeService)
        {
            var globeNode = new GlobeRegion(20);

            foreach (var storedNode in Nodes)
            {
                var scheme = schemeService.GetScheme <ILocationScheme>(storedNode.SchemeSid);
                var node   = new GlobeRegionNode(storedNode.Coords.X, storedNode.Coords.Y, scheme)
                {
                    IsBorder      = storedNode.IsBorder,
                    IsHome        = storedNode.IsHome,
                    IsStart       = storedNode.IsStart,
                    IsTown        = storedNode.IsTown,
                    ObservedState = storedNode.Observed
                };
                globeNode.AddNode(node);
            }

            return(globeNode);
        }
Exemplo n.º 5
0
        private void ValidateRegion(GlobeRegion region, GlobeRegionDraftValue[,] regionDraft, int x, int y)
        {
            // Определяем, является ли узел граничным. На граничных узлах ничего не создаём.
            // Потому что это может вызвать трудности при переходах между провинциями.
            // Например, игрок при переходе сразу может попасть в данж или город.
            // Не отлажен механиз перехода, если часть узлов соседней провинции отсутствует.
            var isBorder = x == 0 || x == LocationBaseSize - 1 || y == 0 || y == LocationBaseSize - 1;

            if (isBorder)
            {
                AddNodeIfBorder(region, x, y);
                return;
            }

            var             currentPatternValue = regionDraft[x, y];
            GlobeRegionNode node = null;

            if (currentPatternValue == null || currentPatternValue.Value.HasFlag(GlobeRegionDraftValueType.Wild))
            {
                // Это означает, что сюда не был применен ни один шаблон или
                // Дикий сектор был указан явно одним из шаблонов.
                // Значит генерируем просто дикий сектор.
                var locationScheme = _schemeService.GetScheme <ILocationScheme>(WILD_SCHEME_SID);
                node = new GlobeRegionNode(x, y, locationScheme);
            }
            else if (currentPatternValue.IsStart)
            {
                var locationScheme = _schemeService.GetScheme <ILocationScheme>(WILD_SCHEME_SID);
                node = new GlobeRegionNode(x, y, locationScheme)
                {
                    IsStart = true
                };
            }
            else if (currentPatternValue.IsHome)
            {
                var locationScheme = _schemeService.GetScheme <ILocationScheme>(CITY_SCHEME_SID);
                node = new GlobeRegionNode(x, y, locationScheme)
                {
                    IsTown = true,
                    IsHome = true
                };
            }
            else if (currentPatternValue.Value.HasFlag(GlobeRegionDraftValueType.Town))
            {
                var locationScheme = _schemeService.GetScheme <ILocationScheme>(CITY_SCHEME_SID);
                node = new GlobeRegionNode(x, y, locationScheme)
                {
                    IsTown = true
                };
            }
            else if (currentPatternValue.Value.HasFlag(GlobeRegionDraftValueType.Dungeon))
            {
                var locationSchemeSids = new[]
                {
                    "rat-hole",
                    "rat-kingdom",
                    "demon-dungeon",
                    "demon-lair",
                    "crypt",
                    "elder-place",
                    "genomass-cave"
                };
                var locationSidIndex = _dice.Roll(0, locationSchemeSids.Length - 1);
                var locationSid      = locationSchemeSids[locationSidIndex];
                var locationScheme   = _schemeService.GetScheme <ILocationScheme>(locationSid);
                node = new GlobeRegionNode(x, y, locationScheme);
            }
            else
            {
                Debug.Assert(true, "При генерации провинции должны все исходы быть предусмотрены.");
            }

            if (node != null)
            {
                region.AddNode(node);
            }
        }