public void BotProtectRisk(int gameRoomId, int turn, int jobType) { var userGameRiskInThisTurn = _service.Game().GetUserGameRisk(gameRoomId, turn).ToList(); var gameBattleInThisTurn = _service.Game().GetGameBattleOpenRisk(gameRoomId, turn).ToList(); var userGameRoom = _service.GameRoom().GetUserGameRoom(gameRoomId, true, jobType); var userId = userGameRoom.UserId; // var protectBotRate = jobType == (int)JobType.ExpertSpecialist ? 10 : 5; foreach (var item in userGameRiskInThisTurn) { //var riskOptionId = 0; var checkRiskInGameBattle = gameBattleInThisTurn.FirstOrDefault(x => x.RiskId == item.RiskId); var riskOptionId = AnalystRiskOption(jobType, checkRiskInGameBattle, item.RiskId); if (riskOptionId > 0) { var botExpertUserGameRisk = new UserGameRisk { RiskId = item.RiskId, Turn = turn, GameRoomId = gameRoomId, UserId = userId, CreateDate = DateTime.UtcNow, CreateBy = userId, RiskOptionId = riskOptionId }; // save bot expert user game Risk _service.Game().AddUserGameRisk(botExpertUserGameRisk); } } //Calculate Protect Risk var currentMoney = userGameRoom.MoneyValue; var botExpertUserGameRiskList = _service.Game().GetUserGameRisk(gameRoomId, turn, userId).ToList(); var moneyForProtectRisk = botExpertUserGameRiskList.Sum(x => x.RiskOption.ActionEffectValue); currentMoney = currentMoney - moneyForProtectRisk.GetValueOrDefault(); _service.GameRoom().UpdateUserGameRoom(userId, gameRoomId, currentMoney, turn); var moneyTotal = CalculateRiskCostToBot(userId, gameRoomId, currentMoney, gameBattleInThisTurn, botExpertUserGameRiskList); // update game room _service.GameRoom().UpdateUserGameRoom(userId, gameRoomId, moneyTotal, turn); var gameDone = _service.Game().CheckMaxTurn(gameRoomId, turn); if (gameDone) { _service.GameRoom().UpdateGameRoomDone(userId, gameRoomId); } }
public UserGameRisk AddUserGameRisk(UserGameRisk entity) { return(_userGameRisk.Add(entity)); }