private void UpdateClientsInLobby() { while (_clientsOfThisGame.Count < MAX_CLIENTS) { foreach (var client in _clientsOfThisGame) { if (client.Client_ID != _clientsOfThisGame[0].Client_ID) { if (_level.PlayerList != null && _level.TrapList != null) { UpdatePack update = new UpdatePack(_level.PlayerList, _level.PlayingField, _level.TrapList); if (client.Player.Life > 0) { SendFeedbackToClient(client.TcpClient, new CommandFeedbackUpdatePack(client.Client_ID, true, update)); } else { SendFeedbackToClient(client.TcpClient, new CommandFeedbackUpdatePack(client.Client_ID, false, update)); } } } } System.Threading.Thread.Sleep(1000); } System.Threading.Thread.CurrentThread.Join(); }
/// <summary> /// Gets the update pack for the host in the lobby. /// </summary> public void GetUpdatePackForLobby() { if (_isConnected) { if (_gameSession_ID != null && _currentStatus == Status.Busy) { CommandServerGetUpdatePackForLobby command = new CommandServerGetUpdatePackForLobby(_client_ID, _gameSession_ID); SendCommandToServer(command); CommandFeedback feedback = EvaluateFeedback(); if (feedback is CommandFeedbackUpdatePack) { _update = ((CommandFeedbackUpdatePack)feedback).Update; } else if (feedback is CommandFeedbackGameException) { throw ((CommandFeedbackGameException)feedback).GameException; } else { throw new CommandNotRecognizedException(); } } } }
/// <summary> /// Get an update of the playing field and wait for the call for your next move. /// It is best to encapsulate it in its own thread so that the client does not get stuck. /// </summary> private void WaitForNextTurn() { _currentStatus = Status.Waiting; CommandFeedback feedback; do { Console.WriteLine("UPDATE..."); feedback = EvaluateFeedback(); if (feedback is CommandFeedbackUpdatePack) { if (((CommandFeedbackUpdatePack)feedback).PlayerAlive == false && _currentStatus != Status.Spectator) { _currentStatus = Status.Spectator; _update = ((CommandFeedbackUpdatePack)feedback).Update; } else { _update = ((CommandFeedbackUpdatePack)feedback).Update; } } } while (feedback is CommandFeedbackUpdatePack); if (feedback is CommandFeedbackYourTurn) { if (_currentStatus != Status.Spectator) { _currentStatus = Status.Busy; System.Threading.Thread.CurrentThread.Abort(); } } }
public CommandFeedbackUpdatePack(string SourceClientID, Boolean playerAlive, UpdatePack update) : base(SourceClientID) { this.PlayerAlive = playerAlive; this.Update = update; IsCompleted = true; // throw new NotImplementedException(); }
public async Task <ApiResult <bool> > UpdatePack(long id, UpdatePack bundle) { var json = JsonConvert.SerializeObject(bundle); var httpContent = new StringContent(json, Encoding.UTF8, "application/json"); var url = $"/api/product/pack/" + $"{id}"; var result = await Update <bool>(url, httpContent); return(result); }
/// <summary> /// Sends update packs at fixed intervals to all clients except the host. /// </summary> private void UpdateClientsInLobby() { while (_clientsOfThisGame[0].IsInGame == false) { try { foreach (var client in _clientsOfThisGame) { if (client.Client_ID != _clientsOfThisGame[0].Client_ID && client.Player != null) { if (_level.PlayerList != null && _level.TrapList != null) { UpdatePack update = new UpdatePack(gameRound, _currentClient.Client_ID, CreatePlayerClientMapping(), _level.PlayingField, _level.TrapList, null); if (client.Player.Life > 0) { SendFeedbackToClient(client.TcpClient, new CommandFeedbackUpdatePack(client.Client_ID, true, update)); Console.WriteLine("Sending Update to: " + client.Player.PlayerName); } else { SendFeedbackToClient(client.TcpClient, new CommandFeedbackUpdatePack(client.Client_ID, false, update)); } } } } } catch (System.Exception) { } System.Threading.Thread.Sleep(1000); } //Send last Update which informs Clients to load the level foreach (var client in _clientsOfThisGame) { if (client.Client_ID != _clientsOfThisGame[0].Client_ID && client.Player != null) { if (_level.PlayerList != null && _level.TrapList != null) { UpdatePack update = new UpdatePack(gameRound, _currentClient.Client_ID, CreatePlayerClientMapping(), _level.PlayingField, _level.TrapList, _level.LevelName); if (client.Player.Life > 0) { SendFeedbackToClient(client.TcpClient, new CommandFeedbackUpdatePack(client.Client_ID, true, update)); Console.WriteLine("Sending Update to: " + client.Player.PlayerName); } else { SendFeedbackToClient(client.TcpClient, new CommandFeedbackUpdatePack(client.Client_ID, false, update)); } } } } System.Threading.Thread.CurrentThread.Join(); }
/// <summary> /// /// </summary> private void UpdateClients() { foreach (var client in _clientsOfThisGame) { UpdatePack update = new UpdatePack(_level.PlayerList, _level.PlayingField, _level.TrapList); if (client.Player.Life > 0) { SendFeedbackToClient(client.TcpClient, new CommandFeedbackUpdatePack(client.Client_ID, true, update)); } else { SendFeedbackToClient(client.TcpClient, new CommandFeedbackUpdatePack(client.Client_ID, false, update)); } } }
/// <summary> /// Sends the update pack for lobby. /// </summary> /// <param name="client_ID">ID of the executing client.</param> /// <param name="session_ID">Session identifier.</param> public static void SendUpdatePackForLobby(string client_ID, string session_ID) { try { if (_gClients[client_ID].IsHost) { UpdatePack pp = _games[session_ID].GetUpdatePackForLobby(); SendFeedbackToClient(_gClients[client_ID].TcpClient, new CommandFeedbackUpdatePack(client_ID, true, pp)); } } catch (Exception e) { SendFeedbackToClient(_gClients[client_ID].TcpClient, new CommandFeedbackGameException(client_ID, e)); } }
public async Task <IActionResult> Update(long id, [FromBody] UpdatePack request) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var result = await _productService.UpdatePack(request); if (!result.IsSuccessed) { return(BadRequest(result)); } return(Ok(result)); }
/// <summary> /// Updates the clients. /// </summary> private void UpdateClients() { foreach (var client in _clientsOfThisGame) { UpdatePack update = new UpdatePack(gameRound, _currentClient.Client_ID, CreatePlayerClientMapping(), _level.PlayingField, _level.TrapList, null); if (client.Player.Life > 0) { //Player alive SendFeedbackToClient(client.TcpClient, new CommandFeedbackUpdatePack(client.Client_ID, true, update)); } else { //Player dead SendFeedbackToClient(client.TcpClient, new CommandFeedbackUpdatePack(client.Client_ID, false, update)); } } }
/// <summary> /// Creates a command that lets your character attack another character. /// </summary> /// <param name="client_ID_From_Enemy">The ClientID of the opponent.</param> public void AttackEnemy(string client_ID_From_Enemy) { if (_isConnected) { if (_gameSession_ID != null && _currentStatus == Status.Busy) { CommandGameAttack command = new CommandGameAttack(_client_ID, client_ID_From_Enemy); SendCommandToServer(command); CommandFeedback feedback = EvaluateFeedback(); if (feedback is CommandFeedbackOK) { feedback = EvaluateFeedback(); if (feedback is CommandFeedbackUpdatePack) { _update = ((CommandFeedbackUpdatePack)feedback).Update; } else { throw new CommandNotRecognizedException(); } } else if (feedback is CommandFeedbackEndOfTurn) { Thread updateThread = new Thread(new ThreadStart(() => WaitForNextTurn())); updateThread.Start(); } else if (feedback is CommandFeedbackGameException) { throw ((CommandFeedbackGameException)feedback).GameException; } else { throw new CommandNotRecognizedException(); } } } }
/// <summary> /// Get an update of the playing field and wait for the call for your next move. /// It is best to encapsulate it in its own thread so that the client does not get stuck. /// </summary> private void WaitForNextTurn() { _currentStatus = Status.Waiting; Reset: CommandFeedback feedback; do { feedback = EvaluateFeedback(); if (feedback is CommandFeedbackUpdatePack) { if (((CommandFeedbackUpdatePack)feedback).PlayerAlive == false && _currentStatus != Status.Spectator) { _currentStatus = Status.Spectator; _update = ((CommandFeedbackUpdatePack)feedback).Update; } else { _update = ((CommandFeedbackUpdatePack)feedback).Update; Console.WriteLine("UPDATE RECEIVED"); } } } while (feedback is CommandFeedbackUpdatePack); if (feedback is CommandFeedbackYourTurn) { if (_currentStatus != Status.Spectator) { _currentStatus = Status.Busy; } else { goto Reset; } } }
public async Task <ApiResult <bool> > UpdatePack(UpdatePack bundle) { var pack = await _context.Packs.FindAsync(bundle.Id); if (pack == null) { return(new ApiErrorResult <bool>("Đóng gói không tồn tại")); } if (bundle.Default) { pack.Default = true; pack.Name = bundle.Name; } else { var count = await _context.Packs .Where(x => x.IdProduct == bundle.IdProduct && x.Id != bundle.Id) .AnyAsync(c => EF.Functions.Collate(c.Name.ToUpper().Trim(), SystemConstants.Collate_AS) == bundle.Name.ToUpper().Trim()); if (!count) { pack.Default = false; pack.Name = bundle.Name; pack.Value = bundle.Value; } else { return(new ApiErrorResult <bool>("Tên đóng gói đã tồn tại")); } } _context.Packs.Update(pack); await _context.SaveChangesAsync(); return(new ApiSuccessResult <bool>()); }
private void Client_UpdateSpecialPack(CustomSpecialPack pack) { UpdatePack?.Invoke(pack); }
public async Task <ApiResult <bool> > UpdatePack(UpdatePack bundle) { var data = await _productApiClient.UpdatePack(bundle.Id, bundle); return(data); }