public async Task <WaveResult> PlayWave(IGameType gameType, Wave currentWave, CancellationToken cancellationToken) { if (cancellationToken.IsCancellationRequested) { return(CreateSkippedResult()); } void onTouch(Vector pos) { var(gridCoords, cell) = gameType.GridAdapter.WorldPositionToGridCoordinates(pos); if (!cell.Available) { return; } var cardsUI = gameUIadapter.CardsUIAdapter; void onCardSelected(Weapon weapon) { cardsUI.OnCardSelected -= onCardSelected; player.PlayerMPGenerator.MP -= weapon.Cost; var loadedWeapon = weaponLoader.LoadWeapon(weapon.WeaponType); loadedWeapon.Position = gridCoords; _ = cardsUI.Hide(cancellationToken); } cardsUI.OnCardSelected += onCardSelected; _ = cardsUI.Show(cancellationToken); } inputService.Setup(); inputService.OnTouch += onTouch; player.PlayerMPGenerator.Init(); int enemiesKilled = 0; var enemies = new IEnemy[currentWave.Enemies.Length]; for (int i = 0; i < currentWave.Enemies.Length && !cancellationToken.IsCancellationRequested && player.Alive; i++) { //await timeAdapter.Delay(1000, cancellationToken); var currentEnemy = currentWave.Enemies[i]; var enemy = enemyLoader.LoadEnemy(currentEnemy.Type); enemy.Animator.Walk(); enemy.Movement.Position = new Vector(currentEnemy.Cell, 0, gameType.GridAdapter.Grid.Width * 3); enemies[i] = enemy; enemy.Init(); await enemy.WaitForCompletion(cancellationToken); enemiesKilled = i; } inputService.OnTouch -= onTouch; inputService.Dispose(); player.PlayerMPGenerator.Stop(); return(new WaveResult() { Alive = player.Alive, VegansKilled = enemiesKilled, }); }