コード例 #1
0
        public AreaMap <Region, WorldRegion> GetRegionalMap(params Region[] regions)
        {
            List <Region> regionList             = regions.ToList();
            int           mainRegionalGroupingId = _groupingKeys.MainRegionalMapGroupingId;

            Region fieldsRegion  = regionList.First(r => r.AreaId == WorldRegion.Fields);
            Region desertRegion  = regionList.First(r => r.AreaId == WorldRegion.Desert);
            Region crystalRegion = regionList.First(r => r.AreaId == WorldRegion.CrystalCaves);
            Region casinoRegion  = regionList.First(r => r.AreaId == WorldRegion.Casino);
            Region castleRegion  = regionList.First(r => r.AreaId == WorldRegion.DarkCastle);

            //note: if there may ever come a time to lock these regions or a reason GetRegionalMap() is called more than once,
            //it could mess with the logic, perhaps
            desertRegion.RegionCompleted  += LogRegionCompleted;
            crystalRegion.RegionCompleted += LogRegionCompleted;
            casinoRegion.RegionCompleted  += LogRegionCompleted;

            MapGrouping <Region, WorldRegion> mainGrouping = new MapGrouping <Region, WorldRegion>(mainRegionalGroupingId,
                                                                                                   desertRegion,
                                                                                                   crystalRegion,
                                                                                                   casinoRegion,
                                                                                                   castleRegion);

            mainGrouping.Lock(m => m.AreaId == WorldRegion.DarkCastle);

            if (!_regionGroupingsDictionary.ContainsKey(mainRegionalGroupingId))
            {
                _regionGroupingsDictionary.Add(mainRegionalGroupingId, mainGrouping);
            }

            List <MapPath <Region, WorldRegion> > mapPaths = new List <MapPath <Region, WorldRegion> >();

            foreach (Region region in regions)
            {
                MapPath <Region, WorldRegion> pathToAdd;
                if (region.AreaId == WorldRegion.DarkCastle)
                {
                    pathToAdd = new MapPath <Region, WorldRegion>(region);
                }
                else
                {
                    pathToAdd = new MapPath <Region, WorldRegion>(region, mainGrouping);
                }

                mapPaths.Add(pathToAdd);
            }

            AreaMap <Region, WorldRegion> ret = new AreaMap <Region, WorldRegion>(fieldsRegion,
                                                                                  mapPaths.ToArray()
                                                                                  );

            mainGrouping.SetParent(ret);

            return(ret);
        }
コード例 #2
0
        public TArea Advance(IDecisionManager decisionManager, Team advancingTeam)
        {
            TArea newArea;

            if (typeof(TArea) == typeof(Region))
            {
                Region currentRegion = CurrentArea as Region;

                RegionCompletedEventArgs e = new RegionCompletedEventArgs(currentRegion);
                currentRegion?.OnRegionCompleted(e);
            }
            if (typeof(TArea) == typeof(SubRegion))
            {
                SubRegion currentSubRegion = CurrentArea as SubRegion;

                SubRegionCompletedEventArgs e = new SubRegionCompletedEventArgs(currentSubRegion);
                currentSubRegion?.OnSubRegionCompleted(e);
            }

            MapPath <TArea, TAreaId> currentPath = MapPaths.First(p => p.From.Equals(CurrentArea));

            List <TArea> availableAreas = currentPath.To.GetAvaialableAreas().ToList();

            if (availableAreas.Count == 0)
            {
                newArea = null;
            }
            else if (availableAreas.Count == 1)
            {
                newArea = availableAreas[0];
            }
            else
            {
                newArea = decisionManager.PickNextArea(currentPath.To, advancingTeam);
            }

            CurrentArea = newArea;
            return(newArea);
        }