/// <inheritdoc/> public void StartGame(StartGameRequest request) { try { lock (this.Padlock) { if (this.LobbyMode != Mode.LobbyMode) { return; } this.Difficulty = request.Difficulty; this.LobbyMode = Mode.InputMode; this.RoundNumber = 1; this.Broadcaster.GameMode(request.StageNumber, (byte)request.Difficulty); this.Broadcaster.InputRound(this.RoundNumber); EnemyDefinitions enemies = EnemyDefinitions.Parse(StorageAPI.DownloadEnemies()); RoundDefinitions rounds = RoundDefinitions.Parse(StorageAPI.DownloadRounds()); Stage stage = Stage.Parse(StorageAPI.DownloadStage(request.StageNumber)); TowerDefinitions towers = TowerDefinitions.Parse(StorageAPI.DownloadTowers()); this.NumberOfRounds = rounds.Rounds.Count; this.EcsContainer = new EcsContainer( this.Broadcaster, request.Difficulty, enemies, rounds, stage, towers ); this.EcsContainer.UpdateClientSystem.UpdateClients(); } } finally { this.ResetInactivityTimer(); } }
/// <summary> /// Initializes a new instance of the <see cref="EcsContainer"/> class. /// </summary> /// <param name="broadcaster"><see cref="Broadcaster"/> to send game messages to.</param> /// <param name="difficulty">Difficulty of this game instance.</param> /// <param name="enemies">Enemy definitions to utilize.</param> /// <param name="rounds">Round definitions to utilize.</param> /// <param name="stage"><see cref="Stage"/> to play on.</param> /// <param name="towers">Tower definitions to utilize.</param> public EcsContainer( Broadcaster broadcaster, StartGameRequest.Difficulties difficulty, EnemyDefinitions enemies, RoundDefinitions rounds, Stage stage, TowerDefinitions towers ) { this.world = new EcsWorld(); this.systems = new EcsSystems(this.world); Dictionary <string, EnemyType> enemyTypeMap = new Dictionary <string, EnemyType>(); foreach (EnemyType enemyType in enemies.EnemyTypes) { enemyTypeMap.Add(enemyType.Name, enemyType); } GameComponent gameSettings = new GameComponent() { Broadcaster = broadcaster, EnemyTypeMap = enemyTypeMap, Stage = stage, TickDuration = 1d / TickNumber, Time = 0d, }; switch (difficulty) { case StartGameRequest.Difficulties.EASY: gameSettings.TowerCostFactor = 0.8d; gameSettings.TowerSaleFactor = 0.9d; break; case StartGameRequest.Difficulties.MEDIUM: gameSettings.TowerCostFactor = 1.0d; gameSettings.TowerSaleFactor = 0.8d; break; case StartGameRequest.Difficulties.HARD: gameSettings.TowerCostFactor = 1.2d; gameSettings.TowerSaleFactor = 0.6d; break; } // Init _ = this.systems.Add(new GameInitializeSystem(gameSettings)); _ = this.systems.Add(new PlayerInitializeSystem()); // Input this.PlaceEnemySystem = new PlaceEnemySystem(rounds); _ = this.systems.Add(this.PlaceEnemySystem); this.PlaceTowerSystem = new PlaceTowerSystem(towers); _ = this.systems.Add(this.PlaceTowerSystem); this.SellTowerSystem = new SellTowerSystem(); _ = this.systems.Add(this.SellTowerSystem); this.UpdateClientSystem = new UpdateClientSystem(); _ = this.systems.Add(this.UpdateClientSystem); // Pre-frame _ = this.systems.Add(new TimeSystem()); // Frame _ = this.systems.Add(new ShootingSystem()); _ = this.systems.Add(new ImpactTimerSystem()); _ = this.systems.Add(new ReloadSystem()); _ = this.systems.Add(new PathMoveSystem()); _ = this.systems.Add(new HurtPlayerSystem()); // Post-frame _ = this.systems.Add(new EndRoundSystem(this)); // Debug _ = this.systems.ProcessInjects(); this.systems.Init(); }