public async Task CreateSectorAsync(int mapSize) { var mapFactory = (FuncMapFactory)Container.GetInstance <IMapFactory>(); mapFactory.SetFunc(async() => { var map = await SquareMapFactory.CreateAsync(mapSize); return(map); }); var sectorManager = Container.GetInstance <ISectorManager>(); var sectorGenerator = Container.GetInstance <ISectorGenerator>(); var humanPlayer = Container.GetInstance <HumanPlayer>(); var locationScheme = new TestLocationScheme { SectorLevels = new ISectorSubScheme[] { new TestSectorSubScheme { RegularMonsterSids = new[] { "rat" }, } } }; var globeNode = new GlobeRegionNode(0, 0, locationScheme); humanPlayer.GlobeNode = globeNode; await sectorManager.CreateSectorAsync(); }
public async System.Threading.Tasks.Task CreateAsync() { var sectorManager = _container.GetInstance <ISectorManager>(); var playerState = _container.GetInstance <ISectorUiState>(); var schemeService = _container.GetInstance <ISchemeService>(); var humanPlayer = _container.GetInstance <HumanPlayer>(); var actorManager = _container.GetInstance <IActorManager>(); var humanActorTaskSource = _container.GetInstance <IHumanActorTaskSource>(); var sectorGenerator = _container.GetInstance <ISectorGenerator>(); var locationScheme = new TestLocationScheme { SectorLevels = new ISectorSubScheme[] { new TestSectorSubScheme { RegularMonsterSids = new[] { "rat" }, RareMonsterSids = new[] { "rat" }, ChampionMonsterSids = new[] { "rat" }, RegionCount = 20, RegionSize = 20, IsStart = true, ChestDropTableSids = new[] { "survival", "default" }, RegionChestCountRatio = 9, TotalChestCount = 20 } } }; var globeNode = new GlobeRegionNode(0, 0, locationScheme); humanPlayer.GlobeNode = globeNode; await sectorManager.CreateSectorAsync(); var personScheme = schemeService.GetScheme <IPersonScheme>("human-person"); var playerActorStartNode = sectorManager.CurrentSector.Map.Regions .SingleOrDefault(x => x.IsStart).Nodes .First(); var playerActorVm = CreateHumanActorVm(humanPlayer, personScheme, actorManager, playerActorStartNode); //Лучше централизовать переключение текущего актёра только в playerState playerState.ActiveActor = playerActorVm; humanActorTaskSource.SwitchActor(playerState.ActiveActor.Actor); }
public async Task CreateSectorAsync(int mapSize) { var mapFactory = (FuncMapFactory)Container.GetInstance <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 = Container.GetInstance <ISectorManager>(); var humanPlayer = Container.GetInstance <HumanPlayer>(); var locationScheme = new TestLocationScheme { SectorLevels = new ISectorSubScheme[] { new TestSectorSubScheme { RegularMonsterSids = new[] { "rat" }, } } }; var globeNode = new GlobeRegionNode(0, 0, locationScheme); humanPlayer.GlobeNode = globeNode; await sectorManager.CreateSectorAsync(); }
public void IterationSetup() { var serviceCollection = new ServiceCollection(); // инстанцируем явно, чтобы обеспечить одинаковый рандом для всех запусков тестов. serviceCollection.AddSingleton <IDice>(factory => new Dice(123)); serviceCollection.AddSingleton <IDecisionSource, DecisionSource>(); serviceCollection.AddSingleton <IRoomGeneratorRandomSource, RoomGeneratorRandomSource>(); serviceCollection.AddSingleton <ISchemeService, SchemeService>(); serviceCollection.AddSingleton <ISchemeServiceHandlerFactory, SchemeServiceHandlerFactory>(); serviceCollection.AddSingleton <IPropFactory, PropFactory>(); serviceCollection.AddSingleton <IDropResolver, DropResolver>(); serviceCollection.AddSingleton <IDropResolverRandomSource, DropResolverRandomSource>(); serviceCollection.AddSingleton <IPerkResolver, PerkResolver>(); serviceCollection.AddSingleton <ISurvivalRandomSource, SurvivalRandomSource>(); serviceCollection.AddSingleton <IChestGenerator, ChestGenerator>(); serviceCollection.AddSingleton <IChestGeneratorRandomSource, ChestGeneratorRandomSource>(); serviceCollection.AddSingleton <IMonsterGenerator, MonsterGenerator>(); serviceCollection.AddSingleton <IMonsterGeneratorRandomSource, MonsterGeneratorRandomSource>(); serviceCollection.AddSingleton <ICitizenGenerator, CitizenGenerator>(); serviceCollection.AddSingleton <ICitizenGeneratorRandomSource, CitizenGeneratorRandomSource>(); serviceCollection.AddSingleton <ISectorFactory, SectorFactory>(); serviceCollection.AddSingleton <IEquipmentDurableService, EquipmentDurableService>(); serviceCollection.AddSingleton <IEquipmentDurableServiceRandomSource, EquipmentDurableServiceRandomSource>(); serviceCollection.AddSingleton <HumanPlayer>(); serviceCollection.AddSingleton <IBotPlayer, BotPlayer>(); serviceCollection.AddSingleton <ISchemeLocator>(factory => CreateSchemeLocator()); serviceCollection.AddSingleton <IGameLoop, GameLoop>(); serviceCollection.AddSingleton <ICommandManager, QueueCommandManager>(); serviceCollection.AddSingleton <ISectorUiState, SectorUiState>(); serviceCollection.AddSingleton <IActorManager, ActorManager>(); serviceCollection.AddSingleton <IPropContainerManager, PropContainerManager>(); serviceCollection.AddSingleton <IHumanActorTaskSource, HumanActorTaskSource>(); serviceCollection.AddSingleton <MonsterBotActorTaskSource>(); serviceCollection.AddSingleton <ISectorGenerator, SectorGenerator>(); serviceCollection.AddSingleton <IRoomGenerator, RoomGenerator>(); serviceCollection.AddSingleton <IRoomGeneratorRandomSource, RoomGeneratorRandomSource>(); serviceCollection.AddSingleton <IMapFactory, RoomMapFactory>(); serviceCollection.AddSingleton <ITacticalActUsageService, TacticalActUsageService>(); serviceCollection.AddSingleton <ITacticalActUsageRandomSource, TacticalActUsageRandomSource>(); serviceCollection.AddSingleton <ISectorManager, SectorManager>(); serviceCollection.AddSingleton <IWorldManager, WorldManager>(); // Специализированные сервисы для Ui. serviceCollection.AddSingleton <IInventoryState, InventoryState>(); // Комманды актёра. serviceCollection.AddSingleton <MoveCommand>(); serviceCollection.AddSingleton <AttackCommand>(); serviceCollection.AddSingleton <OpenContainerCommand>(); serviceCollection.AddSingleton <NextTurnCommand>(); serviceCollection.AddSingleton <UseSelfCommand>(); // Комадны для UI. serviceCollection.AddSingleton <ShowContainerModalCommand>(); serviceCollection.AddSingleton <ShowInventoryModalCommand>(); serviceCollection.AddSingleton <ShowPerksModalCommand>(); // Специализированные команды для Ui. serviceCollection.AddSingleton <EquipCommand>(); serviceCollection.AddSingleton <PropTransferCommand>(); _serviceProvider = serviceCollection.BuildServiceProvider(); var sectorManager = _serviceProvider.GetService <ISectorManager>(); var playerState = _serviceProvider.GetService <ISectorUiState>(); var moveCommand = _serviceProvider.GetService <MoveCommand>(); var schemeService = _serviceProvider.GetService <ISchemeService>(); var humanPlayer = _serviceProvider.GetService <HumanPlayer>(); var actorManager = _serviceProvider.GetService <IActorManager>(); var humanActorTaskSource = _serviceProvider.GetService <IHumanActorTaskSource>(); var commandManger = _serviceProvider.GetService <ICommandManager>(); var sectorGenerator = _serviceProvider.GetService <ISectorGenerator>(); var locationScheme = new TestLocationScheme { SectorLevels = new ISectorSubScheme[] { new TestSectorSubScheme { RegularMonsterSids = new[] { "rat" }, RegionMonsterCount = 0, RegionCount = 20, RegionSize = 20, IsStart = true, ChestDropTableSids = new[] { "survival", "default" }, RegionChestCountRatio = 9, TotalChestCount = 0 } } }; var globeNode = new GlobeRegionNode(0, 0, locationScheme); humanPlayer.GlobeNode = globeNode; sectorManager.CreateSectorAsync().Wait(); var personScheme = schemeService.GetScheme <IPersonScheme>("human-person"); var playerActorStartNode = sectorManager.CurrentSector.Map.Regions .SingleOrDefault(x => x.IsStart).Nodes .First(); var playerActorVm = CreateHumanActorVm(humanPlayer, personScheme, actorManager, playerActorStartNode); //Лучше централизовать переключение текущего актёра только в playerState // Эта строка не нужна для LightInject. // Он сам внедряет зависимости свойств. Опасная вещь. // DI корки так не делает. playerState.TaskSource = humanActorTaskSource; playerState.ActiveActor = playerActorVm; humanActorTaskSource.SwitchActor(playerState.ActiveActor.Actor); // Эта строка не нужна для LightInject. // Он сам внедряет зависимости свойств. Опасная вещь. // DI корки так не делает. var gameLoop = _serviceProvider.GetService <IGameLoop>(); var monsterTaskSource = _serviceProvider.GetService <MonsterBotActorTaskSource>(); gameLoop.ActorTaskSources = new IActorTaskSource[] { humanActorTaskSource, monsterTaskSource }; }
public async System.Threading.Tasks.Task MoveCommandTestAsync() { var sectorManager = _container.GetInstance <ISectorManager>(); var playerState = _container.GetInstance <ISectorUiState>(); var moveCommand = _container.GetInstance <ICommand>("move-command"); var schemeService = _container.GetInstance <ISchemeService>(); var humanPlayer = _container.GetInstance <HumanPlayer>(); var actorManager = _container.GetInstance <IActorManager>(); var humanActorTaskSource = _container.GetInstance <IHumanActorTaskSource>(); var commandManger = _container.GetInstance <ICommandManager>(); var sectorGenerator = _container.GetInstance <ISectorGenerator>(); var locationScheme = new TestLocationScheme { SectorLevels = new ISectorSubScheme[] { new TestSectorSubScheme { RegularMonsterSids = new[] { "rat" }, RegionCount = 20, RegionSize = 20, IsStart = true, ChestDropTableSids = new[] { "default" }, RegionChestCountRatio = 9 } } }; var globeNode = new GlobeRegionNode(0, 0, locationScheme); humanPlayer.GlobeNode = globeNode; await sectorManager.CreateSectorAsync(); var personScheme = schemeService.GetScheme <IPersonScheme>("human-person"); var playerActorStartNode = sectorManager.CurrentSector.Map.Regions .SingleOrDefault(x => x.IsStart).Nodes .First(); var playerActorVm = CreateHumanActorVm(humanPlayer, personScheme, actorManager, playerActorStartNode); //Лучше централизовать переключение текущего актёра только в playerState playerState.ActiveActor = playerActorVm; humanActorTaskSource.SwitchActor(playerState.ActiveActor.Actor); var currentActorNode = (HexNode)playerState.ActiveActor.Actor.Node; var nextNodes = HexNodeHelper.GetSpatialNeighbors(currentActorNode, sectorManager.CurrentSector.Map.Nodes.Cast <HexNode>()); var moveTargetNode = nextNodes.First(); var nodeViewModel = new TestNodeViewModel { Node = moveTargetNode }; playerState.HoverViewModel = nodeViewModel; playerState.SelectedViewModel = nodeViewModel; commandManger.Push(moveCommand); ICommand command = null; do { command = commandManger.Pop(); try { command?.Execute(); } catch (Exception exception) { throw new InvalidOperationException($"Не удалось выполнить команду {command}.", exception); } } while (command != null); }
public async System.Threading.Tasks.Task IterationSetupAsync() { _container = new ServiceContainer(); // инстанцируем явно, чтобы обеспечить одинаковый рандом для всех запусков тестов. _container.Register <IDice>(factory => new Dice(123), new PerContainerLifetime()); _container.Register <IDecisionSource, DecisionSource>(new PerContainerLifetime()); _container.Register <IRoomGeneratorRandomSource, RoomGeneratorRandomSource>(new PerContainerLifetime()); _container.Register <ISchemeService, SchemeService>(new PerContainerLifetime()); _container.Register <ISchemeServiceHandlerFactory, SchemeServiceHandlerFactory>(new PerContainerLifetime()); _container.Register <IPropFactory, PropFactory>(new PerContainerLifetime()); _container.Register <IDropResolver, DropResolver>(new PerContainerLifetime()); _container.Register <IDropResolverRandomSource, DropResolverRandomSource>(new PerContainerLifetime()); _container.Register <IPerkResolver, PerkResolver>(new PerContainerLifetime()); _container.Register <ISurvivalRandomSource, SurvivalRandomSource>(new PerContainerLifetime()); _container.Register <IChestGenerator, ChestGenerator>(new PerContainerLifetime()); _container.Register <IChestGeneratorRandomSource, ChestGeneratorRandomSource>(new PerContainerLifetime()); _container.Register <IMonsterGenerator, MonsterGenerator>(new PerContainerLifetime()); _container.Register <IMonsterGeneratorRandomSource, MonsterGeneratorRandomSource>(new PerContainerLifetime()); _container.Register <ISectorFactory, SectorFactory>(new PerContainerLifetime()); _container.Register <HumanPlayer>(new PerContainerLifetime()); _container.Register <IBotPlayer, BotPlayer>(new PerContainerLifetime()); _container.Register <ISchemeLocator>(factory => CreateSchemeLocator(), new PerContainerLifetime()); _container.Register <IGameLoop, GameLoop>(new PerContainerLifetime()); _container.Register <ICommandManager, QueueCommandManager>(new PerContainerLifetime()); _container.Register <ISectorUiState, SectorUiState>(new PerContainerLifetime()); _container.Register <IActorManager, ActorManager>(new PerContainerLifetime()); _container.Register <IPropContainerManager, PropContainerManager>(new PerContainerLifetime()); _container.Register <ITraderManager, TraderManager>(new PerContainerLifetime()); _container.Register <IHumanActorTaskSource, HumanActorTaskSource>(new PerContainerLifetime()); _container.Register <IActorTaskSource, MonsterActorTaskSource>(serviceName: "monster", lifetime: new PerContainerLifetime()); _container.Register <ISectorGenerator, SectorGenerator>(new PerContainerLifetime()); _container.Register <IRoomGenerator, RoomGenerator>(new PerContainerLifetime()); _container.Register <IRoomGeneratorRandomSource, RoomGeneratorRandomSource>(new PerContainerLifetime()); _container.Register <IMapFactory, RoomMapFactory>(new PerContainerLifetime()); _container.Register <ITacticalActUsageService, TacticalActUsageService>(new PerContainerLifetime()); _container.Register <ITacticalActUsageRandomSource, TacticalActUsageRandomSource>(new PerContainerLifetime()); _container.Register <ISectorManager, SectorManager>(new PerContainerLifetime()); _container.Register <IWorldManager, WorldManager>(new PerContainerLifetime()); // Специализированные сервисы для Ui. _container.Register <IInventoryState, InventoryState>(new PerContainerLifetime()); // Комманды актёра. _container.Register <ICommand, MoveCommand>(serviceName: "move-command", lifetime: new PerContainerLifetime()); _container.Register <ICommand, AttackCommand>(serviceName: "attack-command", lifetime: new PerContainerLifetime()); _container.Register <ICommand, OpenContainerCommand>(serviceName: "open-container-command", lifetime: new PerContainerLifetime()); _container.Register <ICommand, NextTurnCommand>(serviceName: "next-turn-command", lifetime: new PerContainerLifetime()); _container.Register <ICommand, UseSelfCommand>(serviceName: "use-self-command", lifetime: new PerContainerLifetime()); // Комадны для UI. _container.Register <ICommand, ShowContainerModalCommand>(serviceName: "show-container-modal-command", lifetime: new PerContainerLifetime()); _container.Register <ICommand, ShowInventoryModalCommand>(serviceName: "show-inventory-command", lifetime: new PerContainerLifetime()); _container.Register <ICommand, ShowPerksModalCommand>(serviceName: "show-perks-command", lifetime: new PerContainerLifetime()); // Специализированные команды для Ui. _container.Register <ICommand, EquipCommand>(serviceName: "show-container-modal-command"); _container.Register <ICommand, PropTransferCommand>(serviceName: "show-container-modal-command"); var sectorManager = _container.GetInstance <ISectorManager>(); var playerState = _container.GetInstance <ISectorUiState>(); var moveCommand = _container.GetInstance <ICommand>("move-command"); var schemeService = _container.GetInstance <ISchemeService>(); var humanPlayer = _container.GetInstance <HumanPlayer>(); var actorManager = _container.GetInstance <IActorManager>(); var humanActorTaskSource = _container.GetInstance <IHumanActorTaskSource>(); var commandManger = _container.GetInstance <ICommandManager>(); var sectorGenerator = _container.GetInstance <ISectorGenerator>(); var locationScheme = new TestLocationScheme { SectorLevels = new ISectorSubScheme[] { new TestSectorSubScheme { RegularMonsterSids = new[] { "rat" }, RegionCount = 20, RegionSize = 20, IsStart = true, ChestDropTableSids = new[] { "survival", "default" }, RegionChestCountRatio = 9, TotalChestCount = 20 } } }; var globeNode = new GlobeRegionNode(0, 0, locationScheme); humanPlayer.GlobeNode = globeNode; await sectorManager.CreateSectorAsync(); var personScheme = schemeService.GetScheme <IPersonScheme>("human-person"); var playerActorStartNode = sectorManager.CurrentSector.Map.Regions .SingleOrDefault(x => x.IsStart).Nodes .First(); var playerActorVm = CreateHumanActorVm(humanPlayer, personScheme, actorManager, playerActorStartNode); //Лучше централизовать переключение текущего актёра только в playerState playerState.ActiveActor = playerActorVm; humanActorTaskSource.SwitchActor(playerState.ActiveActor.Actor); }
public void IterationSetup() { _container = new ServiceContainer(); // инстанцируем явно, чтобы обеспечить одинаковый рандом для всех запусков тестов. _container.Register <IDice>(factory => new LinearDice(123), new PerContainerLifetime()); _container.Register <IDecisionSource, DecisionSource>(new PerContainerLifetime()); _container.Register <IRoomGeneratorRandomSource, RoomGeneratorRandomSource>(new PerContainerLifetime()); _container.Register <ISchemeService, SchemeService>(new PerContainerLifetime()); _container.Register <ISchemeServiceHandlerFactory, SchemeServiceHandlerFactory>(new PerContainerLifetime()); _container.Register <IPropFactory, PropFactory>(new PerContainerLifetime()); _container.Register <IDropResolver, DropResolver>(new PerContainerLifetime()); _container.Register <IDropResolverRandomSource, DropResolverRandomSource>(new PerContainerLifetime()); _container.Register <IPerkResolver, PerkResolver>(new PerContainerLifetime()); _container.Register <ISurvivalRandomSource, SurvivalRandomSource>(new PerContainerLifetime()); _container.Register <IChestGenerator, ChestGenerator>(new PerContainerLifetime()); _container.Register <IChestGeneratorRandomSource, ChestGeneratorRandomSource>(new PerContainerLifetime()); _container.Register <IMonsterGenerator, MonsterGenerator>(new PerContainerLifetime()); _container.Register <IMonsterGeneratorRandomSource, MonsterGeneratorRandomSource>(new PerContainerLifetime()); _container.Register <ICitizenGenerator, CitizenGenerator>(new PerContainerLifetime()); _container.Register <ICitizenGeneratorRandomSource, CitizenGeneratorRandomSource>(new PerContainerLifetime()); _container.Register <ISectorFactory, SectorFactory>(new PerContainerLifetime()); _container.Register <IEquipmentDurableService, EquipmentDurableService>(new PerContainerLifetime()); _container.Register <IEquipmentDurableServiceRandomSource, EquipmentDurableServiceRandomSource>(new PerContainerLifetime()); _container.Register <HumanPlayer>(new PerContainerLifetime()); _container.Register <IBotPlayer, BotPlayer>(new PerContainerLifetime()); _container.Register <ISchemeLocator>(factory => CreateSchemeLocator(), new PerContainerLifetime()); _container.Register <IGameLoop, GameLoop>(new PerContainerLifetime()); _container.Register <ICommandManager, QueueCommandManager>(new PerContainerLifetime()); _container.Register <ISectorUiState, SectorUiState>(new PerContainerLifetime()); _container.Register <IActorManager, ActorManager>(new PerContainerLifetime()); _container.Register <IPropContainerManager, PropContainerManager>(new PerContainerLifetime()); _container.Register <IHumanActorTaskSource, HumanActorTaskSource>(new PerContainerLifetime()); _container.Register <MonsterBotActorTaskSource>(lifetime: new PerContainerLifetime()); _container.Register <ISectorGenerator, SectorGenerator>(new PerContainerLifetime()); _container.Register <IRoomGenerator, RoomGenerator>(new PerContainerLifetime()); _container.Register <IRoomGeneratorRandomSource, RoomGeneratorRandomSource>(new PerContainerLifetime()); _container.Register <IMapFactory, RoomMapFactory>(new PerContainerLifetime()); _container.Register <IMapFactorySelector, LightInjectSwitchMapFactorySelector>(new PerContainerLifetime()); _container.Register <ITacticalActUsageService, TacticalActUsageService>(new PerContainerLifetime()); _container.Register <ITacticalActUsageRandomSource, TacticalActUsageRandomSource>(new PerContainerLifetime()); _container.Register <ISectorManager, SectorManager>(new PerContainerLifetime()); _container.Register <IWorldManager, WorldManager>(new PerContainerLifetime()); // Специализированные сервисы для Ui. _container.Register <IInventoryState, InventoryState>(new PerContainerLifetime()); // Комманды актёра. _container.Register <MoveCommand>(lifetime: new PerContainerLifetime()); var sectorManager = _container.GetInstance <ISectorManager>(); var playerState = _container.GetInstance <ISectorUiState>(); var schemeService = _container.GetInstance <ISchemeService>(); var humanPlayer = _container.GetInstance <HumanPlayer>(); var actorManager = _container.GetInstance <IActorManager>(); var humanActorTaskSource = _container.GetInstance <IHumanActorTaskSource>(); var locationScheme = new TestLocationScheme { SectorLevels = new ISectorSubScheme[] { new TestSectorSubScheme { RegularMonsterSids = new[] { "rat" }, RegionMonsterCount = 0, RegionCount = 20, RegionSize = 20, IsStart = true, ChestDropTableSids = new[] { "survival", "default" }, RegionChestCountRatio = 9, TotalChestCount = 0 } } }; var globeNode = new GlobeRegionNode(0, 0, locationScheme); humanPlayer.GlobeNode = globeNode; sectorManager.CreateSectorAsync().Wait(); var personScheme = schemeService.GetScheme <IPersonScheme>("human-person"); var playerActorStartNode = sectorManager.CurrentSector.Map.Regions .SingleOrDefault(x => x.IsStart).Nodes .First(); var playerActorVm = CreateHumanActorVm(humanPlayer, personScheme, actorManager, playerActorStartNode); //Лучше централизовать переключение текущего актёра только в playerState playerState.ActiveActor = playerActorVm; humanActorTaskSource.SwitchActor(playerState.ActiveActor.Actor); }