public void GetGroupingMethod_ReturnsSingleton() { //arrange List <Region> regions = _regionFactory.GetRegions(EnumHelperMethods.GetAllValuesForEnum <WorldRegion>()).ToList(); _mapManager.GetRegionalMap(regions.ToArray()); Region desertRegion = regions.First(r => r.AreaId == WorldRegion.Desert); _mapManager.GetSubRegionalMap(WorldRegion.Desert, desertRegion.SubRegions); int regionalGroupingId = Globals.GroupingKeys.MainRegionalMapGroupingId; int groupingId = Globals.GroupingKeys.FirstDesertGroupingId; MapGrouping <SubRegion, WorldSubRegion> originalSubRegionalGrouping = _mapManager.GetGrouping <SubRegion, WorldSubRegion>(groupingId); originalSubRegionalGrouping.Lock(sr => sr.AreaId != WorldSubRegion.Oasis); MapGrouping <Region, WorldRegion> originalRegionalGrouping = _mapManager.GetGrouping <Region, WorldRegion>(regionalGroupingId); originalRegionalGrouping.Lock(sr => sr.AreaId != WorldRegion.Casino); //act MapGrouping <SubRegion, WorldSubRegion> secondSubRegionalGrouping = _mapManager.GetGrouping <SubRegion, WorldSubRegion>(groupingId); MapGrouping <Region, WorldRegion> secondRegionalGrouping = _mapManager.GetGrouping <Region, WorldRegion>(regionalGroupingId); //Assert Assert.AreEqual(1, secondSubRegionalGrouping.GetAvaialableAreas().Count()); Assert.AreEqual(1, secondRegionalGrouping.GetAvaialableAreas().Count()); }
private SubRegion ChooseDesertSubRegions(Team advancingTeam, MapGrouping <SubRegion, WorldSubRegion> grouping) { SubRegion ret; if (_groupingChoicesDictionary.ContainsKey(Globals.GroupingKeys.FirstDesertGroupingId)) { WorldSubRegion selectedRegion = _groupingChoicesDictionary[Globals.GroupingKeys.FirstDesertGroupingId]; ret = grouping.GetAvaialableAreas().First(sr => sr.AreaId == selectedRegion); } else { HumanFighter mazeSolver = advancingTeam.Fighters.OfType <HumanFighter>() .First(f => f.PersonalityFlags.Contains(PersonalityFlag.MazeSolver)); HumanFighter notMazeSolver = advancingTeam.Fighters.OfType <HumanFighter>() .First(f => !f.PersonalityFlags.Contains(PersonalityFlag.MazeSolver)); IEnumerable <WorldSubRegion> firstGroupingSubRegions = WorldSubRegions.GetSubRegionsByGroupingId(Globals.GroupingKeys.FirstDesertGroupingId); IEnumerable <MenuAction> firstGroupingMenuActions = firstGroupingSubRegions.Select( sr => new TypedMenuAction <WorldSubRegion>(sr, GetDisplayTextForMenu(sr), GetCommandTextForMenu(sr), isHidden: sr == WorldSubRegion.Oasis)); IMenu firstGroupingMenu = _menuFactory.GetMenu(MenuType.NonSpecificMenu, _input, _output, allowHelp: false, allowBack: false, allowStatus: false, prompt: $"{Globals.OwnerReplaceText}: We should focus on forming a strategy for our next battle, we should...", errorText: Globals.GenericErrorMessage, menuActions: firstGroupingMenuActions.ToList(), chanceService: _chanceService, shuffleOptions: true); firstGroupingMenu.Build(mazeSolver, null, null, null); TypedMenuSelection <WorldSubRegion> firstMenuSelection = firstGroupingMenu.GetInput() as TypedMenuSelection <WorldSubRegion>; if (firstMenuSelection == null) { throw new InvalidCastException( "DecisionManager.ChooseDesertSubRegions() should have generated menus that would return a TypedMenuSeleciton<WorldSubRegion> but it did not!"); } WorldSubRegion firstSelectedSubRegionEnum = firstMenuSelection.Item; grouping.Lock(sr => sr.AreaId != firstSelectedSubRegionEnum); _relationshipManager.UpdateRelationship(mazeSolver, WorldSubRegions.GetGodEnumBySubRegion(firstSelectedSubRegionEnum), 1); _groupingChoicesDictionary.Add(Globals.GroupingKeys.FirstDesertGroupingId, firstSelectedSubRegionEnum); IEnumerable <WorldSubRegion> secondGroupingSubRegions = WorldSubRegions.GetSubRegionsByGroupingId(Globals.GroupingKeys.SecondDesertGroupingId); IEnumerable <MenuAction> secondGroupingMenuActions = secondGroupingSubRegions.Select( sr => new TypedMenuAction <WorldSubRegion>(sr, GetDisplayTextForMenu(sr), GetCommandTextForMenu(sr), isHidden: sr == WorldSubRegion.BeastTemple)); IMenu secondGroupingMenu = _menuFactory.GetMenu(MenuType.NonSpecificMenu, _input, _output, allowHelp: false, allowBack: false, allowStatus: false, prompt: $"{Globals.OwnerReplaceText}: I was thinking about how we could improve, what if we...", errorText: Globals.GenericErrorMessage, menuActions: secondGroupingMenuActions.ToList(), chanceService: _chanceService, shuffleOptions: true); secondGroupingMenu.Build(notMazeSolver, null, null, null); TypedMenuSelection <WorldSubRegion> secondMenuSelection = secondGroupingMenu.GetInput() as TypedMenuSelection <WorldSubRegion>; if (secondMenuSelection == null) { throw new InvalidCastException( "DecisionManager.ChooseDesertSubRegions() should have generated menus that would return a TypedMenuSeleciton<WorldSubRegion> but it did not!"); } WorldSubRegion secondSelectedSubRegionEnum = secondMenuSelection.Item; grouping.Parent.MapPaths.First(path => path.To.GroupingId == Globals.GroupingKeys.SecondDesertGroupingId) .To.Lock(sr => sr.AreaId != secondSelectedSubRegionEnum); _relationshipManager.UpdateRelationship(notMazeSolver, WorldSubRegions.GetGodEnumBySubRegion(secondSelectedSubRegionEnum), 1); _groupingChoicesDictionary.Add(Globals.GroupingKeys.SecondDesertGroupingId, secondSelectedSubRegionEnum); ret = grouping.GetAvaialableAreas().First(sr => sr.AreaId == firstSelectedSubRegionEnum); } return(ret); }
public void CorrectlyMovesToNextSubRegion_TwoNextSubRegionsButOneIsLocked() { const MagicType firstBossEggType = MagicType.Fire; const MagicType secondBossEggType = MagicType.Ice; TeamConfiguration firstBossConfiguration = new TeamConfiguration(new EnemyConfiguration(FighterType.Egg, 1, firstBossEggType)); SubRegion subRegionA = new SubRegion(WorldSubRegion.Fields, 0, new ChanceEvent <int> [0], new FighterType[0], new BattlefieldConfiguration(firstBossConfiguration)); const string secondRegionIntro = "Who wants donuts?!?"; TeamConfiguration secondBossConfiguration = new TeamConfiguration(new EnemyConfiguration(FighterType.Egg, 1, secondBossEggType)); SubRegion subRegionB = new SubRegion(WorldSubRegion.DesertCrypt, 0, new ChanceEvent <int> [0], new FighterType[0], new BattlefieldConfiguration(secondBossConfiguration), regionIntro: secondRegionIntro); const string lockedRegionIntro = "watch me do a flip!"; TeamConfiguration lockedRegionConfiguration = new TeamConfiguration(new EnemyConfiguration(FighterType.Goblin, 1)); SubRegion lockedSubRegion = new SubRegion(WorldSubRegion.AncientLibrary, 0, new ChanceEvent <int> [0], new FighterType[0], new BattlefieldConfiguration(lockedRegionConfiguration), regionIntro: lockedRegionIntro); SubRegion[] subRegions = { subRegionA, subRegionB, lockedSubRegion }; Region fakeFieldsRegion = new Region(WorldRegion.Fields, new BattleMove[0], subRegions); _regionFactory.SetRegion(WorldRegion.Fields, fakeFieldsRegion); AreaMap <Region, WorldRegion> regionMap = new AreaMap <Region, WorldRegion>(fakeFieldsRegion, new MapPath <Region, WorldRegion>(fakeFieldsRegion)); MapGrouping <SubRegion, WorldSubRegion> grouping = new MapGrouping <SubRegion, WorldSubRegion>(0, subRegionB, lockedSubRegion); grouping.Lock(sr => sr.AreaId == WorldSubRegion.AncientLibrary); AreaMap <SubRegion, WorldSubRegion> subRegionMap = new AreaMap <SubRegion, WorldSubRegion>(subRegionA, new MapPath <SubRegion, WorldSubRegion>(subRegionA, grouping)); _mapManager.SetRegionalMap(regionMap); _mapManager.SetSubRegionalMap(WorldRegion.Fields, subRegionMap); _regionManager = GetRegionManager(); TestEnemyFighter target = (TestEnemyFighter)TestFighterFactory.GetFighter(TestFighterType.TestEnemy, 1); target.SetHealth(1, 0); _humanFighter1.SetMove(_basicAttackMove, 1); _humanFighter1.SetMove(_runawayMove, 1); _humanFighter1.SetMoveTarget(target); _humanFighter2.SetMove(_doNothingMove); _chanceService.PushAttackHitsNotCrit(); _regionManager.Battle(_battleManager, _humanTeam); MockOutputMessage[] outputs = _output.GetOutputs(); Assert.Null(outputs.FirstOrDefault(o => o.Message == lockedRegionIntro + "\n")); List <Team> enemyTeams = _battleManager.GetAllEnemyTeams(); Assert.AreEqual(2, enemyTeams.Count); Goblin lockedBoss = enemyTeams[1].Fighters[0] as Goblin; Assert.Null(lockedBoss); }