private void PlayRound(int round) { PvpFights = GenerateFights(AliveClients); foreach (var gamePlayer in GamePlayers) { gamePlayer.AddXp(1); gamePlayer.ChangeMoney(5); if (!gamePlayer.ShopLock) { RollShop(gamePlayer); } } foreach (var client in AliveClients) { SendRound(client, round); SendGamePlayersHp(client); SendXp(client); if (client.GamePlayer.IsNewLvl()) { SendLvlUp(client); } SendMoney(client); SendShop(client); AddCommandLvlUp(client); AddCommandShopBuy(client); AddCommandShopRoll(client); AddCommandBuyShip(client); AddCommandShipReposition(client); AddCommandAddShipPart(client); AddCommandShopLock(client); AddCommandBagItemReposition(client); AddCommandSellBagItem(client); SendPhaseBuying(client); SendOpponent(client); } const int buySeconds = 60; for (var currentSecond = 0; currentSecond < buySeconds; currentSecond++) { var timeLeft = buySeconds - currentSecond; if (currentSecond % (buySeconds / 3) == 0) { AliveClients.ForEach(client => SendTime(client, timeLeft)); } Thread.Sleep(1000); } // const int positioningSeconds = 10; // foreach (var client in AliveClients) { // RemoveCommandLvlUp(client); // RemoveCommandShopBuy(client); // RemoveCommandShopRoll(client); // RemoveCommandBuyShip(client); // RemoveCommandAddShipPart(client); // RemoveCommandShopLock(client); // RemoveCommandBagItemReposition(client); // RemoveCommandSellBagItem(client); // SendPhasePositioning(client); // } // for (var currentSecond = 0; currentSecond < positioningSeconds; currentSecond++) { // var timeLeft = positioningSeconds - currentSecond; // if (currentSecond % (positioningSeconds / 3) == 0) { // AliveClients.ForEach(client => SendTime(client, timeLeft)); // } // Thread.Sleep(1000); // } const int fightDurationSeconds = 20; foreach (var client in AliveClients) { RemoveCommandShipReposition(client); SendPhaseFighting(client); } var fightRandomSeed = _random.Next(); var fightTasks = new List <Task <FightResult> >(); foreach (var pvpFight in PvpFights) { var fightTask = new Task <FightResult>(() => Fight.CalcWinner(pvpFight.PvpArena, fightDurationSeconds, new Random(fightRandomSeed))); fightTasks.Add(fightTask); fightTask.Start(); } //todo w8 clients Loading foreach (var client in AliveClients) { SendStartFight(client, fightRandomSeed); } for (var currentSecond = 0; currentSecond < fightDurationSeconds; currentSecond++) { var timeLeft = fightDurationSeconds - currentSecond; Thread.Sleep(1000); } foreach (var fightTask in fightTasks) { fightTask.Wait(); var loserClient = AliveClients.Find(client => client.GamePlayer == fightTask.Result.Loser); loserClient?.GamePlayer.ChangeHp(-fightTask.Result.Damage); // SendHp(loserClient); if (fightTask.Result.Tie) { var winnerClient = AliveClients.Find(client => client.GamePlayer == fightTask.Result.Winner); winnerClient?.GamePlayer.ChangeHp(-fightTask.Result.Damage); // SendHp(winnerClient); } } var diedClients = AliveClients.Where(client => client.GamePlayer.Hp <= 0).ToList(); foreach (var networkClient in diedClients) { LeaveClient(networkClient); LastDead = networkClient; } foreach (var networkClient in diedClients) { SendGameEnd(networkClient, GamePlayers.Count + 1); } if (AliveClients.Count == 1) { var lastClient = AliveClients.First(); LeaveClient(lastClient); SendGameEnd(lastClient, 1); } }