public int AnalystRiskOption(int jobType, GameBattle gameBattle, int riskId) { var riskOptionId = 0; if (jobType == (int)JobType.ExpertSpecialist) { if (gameBattle != null) { //Opportunity to expert Specialist Thinking var expertSpecialistRandomLevel = CommonFunction.RandomNumber(1, 10); if (expertSpecialistRandomLevel > 4) // random 5-10 จะได้ option ที่ถูก { riskOptionId = gameBattle.RiskOptionId; } else { // ถ้า random 0-4 จะต้องมาสุ่มเลือกว่าจะเลือก level 0 - 2 var randomLevel = CommonFunction.RandomNumber(0, 2); var allRiskOption = _service.Risk().GetAllRiskOptionByRiskId(riskId, randomLevel); if (allRiskOption.Any()) { riskOptionId = allRiskOption.FirstOrDefault().RiskOptionId; } } } else { // ถ้าหาไม่เจอ ให้ลองเสี่ยง 0 - 1 var expertRandomLevelIgnore = CommonFunction.RandomNumber(0, 1); var allRiskOption = _service.Risk().GetAllRiskOptionByRiskId(riskId, expertRandomLevelIgnore); if (allRiskOption.Any()) { riskOptionId = allRiskOption.FirstOrDefault().RiskOptionId; } } } else if (jobType == (int)JobType.Newbies) { var newbiesRandomLevel = CommonFunction.RandomNumber(0, 1); var allRiskOption = _service.Risk().GetAllRiskOptionByRiskId(riskId, newbiesRandomLevel); if (allRiskOption.Any()) { riskOptionId = allRiskOption.FirstOrDefault().RiskOptionId; } } return(riskOptionId); }
public ActionResult Detail(int gameRoomId) { // get gameroom detail and user protect risk var userId = Singleton.User().UserId; var data = _service.GameRoom().GetGameHistoryDetail(gameRoomId); var model = new GameHistoryViewModel { GameRoom = data, RiskOptionList = _service.Risk().GetAllRiskOption().ToList() }; return(View(model)); }
// GET: AdminDashboard public ActionResult Index() { var data = _service.Risk().GetAll(); var model = new RiskDataModel { RiskData = data.Select(x => new RiskData { RiskId = x.RiskId, Name = x.RiskName, RiskDetail = x.RiskDetail, RiskType = Enum.GetName(typeof(Const.RiskType), (int)x.RiskType) }).ToList() }; return(View(model)); }
// GET: Story public ActionResult Index(int id) { System.Threading.Thread.Sleep(2000); // ReCallUserGameRoom(id); var gameRoom = _service.GameRoom().GetRoomById(id); var gameBattleRisk = _service.Game().GetGameBattleByGameRoomId(id); var risk = _service.Risk().GetAll().OrderBy(x => Guid.NewGuid()).Take(10); var riskList = new List <Risk>(); riskList.AddRange(risk); riskList.AddRange(gameBattleRisk.GroupBy(x => x.RiskId).Select(x => x.FirstOrDefault().Risk)); var model = new GameRoomModel { GameRoomId = id, SoftwareType = gameRoom.SoftwareType, MoneyInGame = gameRoom.MoneyValue, Risks = riskList.GroupBy(x => x.RiskId).Select(x => x.FirstOrDefault()).ToList() }; return(View("Index", model)); }
//[HttpPost] //public ActionResult OpenRisk(FormCollection form) //{ // var selectedRisk = form.AllKeys.Where(x => x.Contains("riskoption")).ToList(); // var moneySummary = 0; // if (selectedRisk.Any()) // { // foreach (var item in selectedRisk) // { // var moneyValue = form[item]; // if (moneyValue != null) // { // moneySummary += int.Parse(moneyValue); // } // //save database // } // } // var total = Singleton.User().Money - moneySummary; // UpdateGameUser(total); // ViewBag.Money = total; // return View(); //} public ActionResult OpenRisk() { // check risk, and reduce money var moneyTotal = Singleton.Game().Money; var model = new GameBattleViewModel(); var openRisk = _service.Game().GetGameBattleOpenRisk(Singleton.Game().GameRoomId, Singleton.Game().Turn); if (openRisk.Any()) { model.GameBattles = openRisk.ToList(); var gameBattleData = _service.Game().GetGameBattleData(openRisk.ToList()); var javaScriptSearilizer = new JavaScriptSerializer(); var searializedObject = javaScriptSearilizer.Serialize(gameBattleData); model.OpenRiskGameBattleModelArray = searializedObject; var userGameRisk = _service.Game().GetUserGameRisk(Singleton.Game().GameRoomId, Singleton.Game().Turn, Singleton.Game().UserId); model.UserGameRisk = userGameRisk.ToList(); foreach (var item in model.GameBattles) { var userGameBattleData = new UserGameBattleData { GameBattle = item, ProtectStatus = ProtecStatus.Lose.ToString() }; var effectItemMoney = item.Ratio.GetValueOrDefault() * item.ActionEffectValue.GetValueOrDefault(); var riskProtect = userGameRisk.FirstOrDefault(x => x.RiskId == item.RiskId); var effectMoney = 0; if (riskProtect != null && riskProtect.RiskOption.RiskLevel != (int)RiskGameLevel.ZeroLevel) { if (riskProtect.RiskOption.RiskLevel != item.RiskOption.RiskLevel) { if (riskProtect.RiskOption.RiskLevel > item.RiskOption.RiskLevel) { // ไม่ต้องจ่าย ป้องกันได้ 100% //moneyTotal = Singleton.Game().Money; userGameBattleData.ProtectStatus = ProtecStatus.Win.ToString(); } else { if (riskProtect.RiskOption.RiskLevel == (int)RiskGameLevel.ThirdLevel) { //ป้องกัน 100% // moneyTotal = Singleton.Game().Money; userGameBattleData.ProtectStatus = ProtecStatus.Win.ToString(); } else if (riskProtect.RiskOption.RiskLevel == (int)RiskGameLevel.SecondLevel) { //ป้องกัน 50% จ่าย 50% effectMoney = (int)(effectItemMoney * 0.5); moneyTotal = moneyTotal - (int)(effectItemMoney * 0.5); } else if (riskProtect.RiskOption.RiskLevel == (int)RiskGameLevel.FirstLevel) { //ป้องกัน 25% จ่าย 75% effectMoney = (int)(effectItemMoney * 0.75); moneyTotal = moneyTotal - (int)(effectItemMoney * 0.75); } else if (riskProtect.RiskOption.RiskLevel == (int)RiskGameLevel.ZeroLevel) { effectMoney = (int)(effectItemMoney * 1); moneyTotal = moneyTotal - (int)(effectItemMoney * 1); } } } else { // ถ้าเลือกแล้ว Level เท่ากัน ป้องกันได้ 100% // moneyTotal = Singleton.Game().Money; userGameBattleData.ProtectStatus = ProtecStatus.Draw.ToString(); } } else { // ถ้าไม่ได้เลือก หรือ ไม่ได้ป้องกัน จ่าย 100% effectMoney = effectItemMoney; moneyTotal = moneyTotal - effectItemMoney; } // ถ้าแพ้ และ มีข่าว จะโดนผลกระทบเพิ่ม if (item.RiskNewsId != null && userGameBattleData.ProtectStatus == ProtecStatus.Lose.ToString()) { // fact impact var riskNews = _service.Risk().GetRiskNewsById(item.RiskNewsId.GetValueOrDefault()); if (riskNews != null) { var riskNewsImpactPercent = CommonFunction.RiskImpactFormat(riskNews.RiskNewsImpact.GetValueOrDefault()); var riskNewsImpact = (int)(effectItemMoney * riskNewsImpactPercent); moneyTotal = moneyTotal - riskNewsImpact; effectMoney = effectMoney + riskNewsImpact; userGameBattleData.RiskNewsImpactPercent = riskNewsImpactPercent; userGameBattleData.RiskNewsImpact = riskNewsImpact; // ค่าเงิน } } userGameBattleData.EffectMoney = effectMoney; model.UserGameBattleData.Add(userGameBattleData); } } // get risk selected from db model.GameDone = _service.Game().CheckMaxTurn(Singleton.Game().GameRoomId, Singleton.Game().Turn); var nextTurn = Singleton.Game().Turn; if (!model.GameDone) { nextTurn += 1; } _service.GameRoom().UpdateUserGameRoom(Singleton.Game().UserId, Singleton.Game().GameRoomId, moneyTotal, nextTurn); Singleton.UpdateGameSession(Singleton.Game().Team, Singleton.Game().Project, moneyTotal, nextTurn, Singleton.Game().SoftwareType, Singleton.Game().PlayerImageUrl); return(View(model)); }
public void CreateWaterFallModel(int gameRoomId, int round) { try { var listReq = new List <Risk>(); var listDesign = new List <Risk>(); var listDev = new List <Risk>(); var listQA = new List <Risk>(); var listSupport = new List <Risk>(); var listAll = new List <Risk>(); // getAll Risk with Risk option var risks = _service.Risk().GetAllRiskWithOutZeroLevel().ToList(); listAll.AddRange(risks.Where(x => x.RiskType == (int)RiskType.General)); var generalReq = listAll.OrderBy(x => Guid.NewGuid()).Take(5).ToList(); // separate type listReq.AddRange(risks.Where(x => x.RiskType == (int)RiskType.Requirement)); listReq.AddRange(generalReq); var generalDesign = listAll.OrderBy(x => Guid.NewGuid()).Take(5).ToList(); listDesign.AddRange(risks.Where(x => x.RiskType == (int)RiskType.Design)); listDesign.AddRange(generalDesign); var generalDev = listAll.OrderBy(x => Guid.NewGuid()).Take(5).ToList(); listDev.AddRange(risks.Where(x => x.RiskType == (int)RiskType.Implement)); listDev.AddRange(generalDev); var generalQA = listAll.OrderBy(x => Guid.NewGuid()).Take(5).ToList(); listQA.AddRange(risks.Where(x => x.RiskType == (int)RiskType.Testing)); listQA.AddRange(generalQA); var generalSupport = listAll.OrderBy(x => Guid.NewGuid()).Take(5).ToList(); listSupport.AddRange(risks.Where(x => x.RiskType == (int)RiskType.Support)); listSupport.AddRange(generalSupport); var gameBattleList = new List <GameBattle>(); //take Random var turn = 0; for (int i = 0; i < round; i++) { if (i > 0) { turn += 5; } gameBattleList.AddRange(GenerateWorkProcess(gameRoomId, listReq, ((int)RiskType.Requirement + turn))); gameBattleList.AddRange(GenerateWorkProcess(gameRoomId, listDesign, ((int)RiskType.Design + turn))); gameBattleList.AddRange(GenerateWorkProcess(gameRoomId, listDev, ((int)RiskType.Implement + turn))); gameBattleList.AddRange(GenerateWorkProcess(gameRoomId, listQA, ((int)RiskType.Testing + turn))); gameBattleList.AddRange(GenerateWorkProcess(gameRoomId, listSupport, ((int)RiskType.Support + turn))); } //save DB foreach (var gameBattle in gameBattleList) { _service.Game().SaveGameBattleAsync(gameBattle); } } catch (Exception ex) { } }