Esempio n. 1
0
        public ActionResult Index()
        {
            var data  = _service.GameRoom().GetGameHistory(Singleton.User().UserId);
            var model = new GameHistoryViewModel
            {
                GameRoomList = data.ToList()
            };

            return(View(model));
        }
Esempio n. 2
0
        public JsonResult MultiPlayerGameStart(int id)
        {
            //update start - end
            var gameRoom = _service.GameRoom().GetRoomById(id);

            gameRoom.StartDate = DateTime.UtcNow;
            gameRoom.EndDate   = DateTime.UtcNow.AddMinutes(15);
            _service.GameRoom().UpdateGameRoom(gameRoom);

            var response = CommonFunction.GetResponse(gameRoom != null, string.Empty, gameRoom);

            return(Json(response));
        }
Esempio n. 3
0
        public ActionResult UserGameHistory()
        {
            var userId   = Singleton.User().UserId;
            var gameRoom = _service.GameRoom().GetGameHistory(userId);
            var model    = new GameHistoryViewModel
            {
                GameRoomList = gameRoom.ToList()
            };

            return(View(model));
        }
Esempio n. 4
0
        private void CreateBotExpert(GameRoom gameRoom)
        {
            var userBotNewbies = new User();
            var userBotExpert  = new User();

            using (var context = new DataContext())
            {
                userBotNewbies = context.Users.FirstOrDefault(x => x.BotExpert == (int)JobType.Newbies);
                userBotExpert  = context.Users.FirstOrDefault(x => x.BotExpert == (int)JobType.ExpertSpecialist);
            }

            if (userBotNewbies != null)
            {
                var userGameBotLevel1 = new UserGameRoom
                {
                    GameRoomId   = gameRoom.GameRoomId,
                    PlayerName   = "Junior (Risk Newbies)",
                    JobType      = (int)JobType.Newbies,
                    TurnValue    = 1,
                    MoneyValue   = gameRoom.MoneyValue,
                    ProjectValue = gameRoom.ProjectValue,
                    TeamValue    = gameRoom.TeamValue,
                    GameFinished = null,
                    JoinDate     = DateTime.UtcNow,
                    UserId       = userBotNewbies.UserId,
                    Active       = true,
                    IsBot        = true,
                    ImageUrl     = "/Content/sufee/images/newbies.png"
                };
                _service.GameRoom().SaveUserGameRoomAsync(userGameBotLevel1);
            }

            if (userBotExpert != null)
            {
                var userGameBotLevel3 = new UserGameRoom
                {
                    GameRoomId   = gameRoom.GameRoomId,
                    PlayerName   = "Expert User (Risk Specialist)",
                    JobType      = (int)JobType.ExpertSpecialist,
                    TurnValue    = 1,
                    MoneyValue   = gameRoom.MoneyValue,
                    ProjectValue = gameRoom.ProjectValue,
                    TeamValue    = gameRoom.TeamValue,
                    GameFinished = null,
                    JoinDate     = DateTime.UtcNow,
                    UserId       = userBotExpert.UserId,
                    Active       = true,
                    IsBot        = true,
                    ImageUrl     = "/Content/sufee/images/expert.png"
                };
                _service.GameRoom().SaveUserGameRoomAsync(userGameBotLevel3);
            }
        }
Esempio n. 5
0
        // 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));
        }
Esempio n. 6
0
        //[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));
        }
Esempio n. 7
0
        public ActionResult AddRoom(FormCollection form)
        {
            var roomName            = form["Add.RoomName"];
            var startMoney          = int.Parse(form["Add.StartMoney"]);
            var goal                = int.Parse(form["Add.Goal"]);
            var softwareProcessType = int.Parse(form["Add.SoftwareProcessType"]);
            var playerName          = form["Add.PlayerName"];
            var jobType             = form["Add.JobType"];
            var multiPlayer         = int.Parse(form["Add.MultiPlayer"]);
            var round               = int.Parse(form["Add.Round"]);
            var imageUrl            = form["Add.ImageUrl"];
            var expertPlayer        = form["Add.ExpertPlayer"].ToLower() == "false" ? false : true;
            //Initial Game to Game Battle
            //Set game started

            var gameRoom = _service.GameRoom().AddRoom(new Entity.GameRoom
            {
                Active       = true,
                CreateDate   = DateTime.UtcNow,
                GameRoomName = roomName,
                Goal         = goal,
                MoneyValue   = startMoney,
                Multiplayer  = multiPlayer,
                StartDate    = multiPlayer > 1 ? (DateTime?)null : DateTime.UtcNow,
                EndDate      = multiPlayer > 1 ? (DateTime?)null : DateTime.UtcNow.AddMinutes(15),
                TeamValue    = 2, //if startup
                SoftwareType = softwareProcessType,
                ProjectValue = 0,
                GameRound    = round,
                IncludeBot   = expertPlayer,
                UserId       = Singleton.User().UserId // get from session
            });

            if (gameRoom != null)
            {
                _service.Game().CreateGameAsync(gameRoom.GameRoomId, gameRoom.SoftwareType, gameRoom.GameRound);
                if (multiPlayer > 1)
                {
                    //multiplayer > wait room

                    _service.GameRoom().AddUserGameRoom(new Entity.UserGameRoom
                    {
                        GameRoomId   = gameRoom.GameRoomId,
                        PlayerName   = playerName,
                        JobType      = int.Parse(jobType),
                        MoneyValue   = gameRoom.MoneyValue,
                        ProjectValue = gameRoom.ProjectValue,
                        TeamValue    = gameRoom.TeamValue,
                        TurnValue    = 1,
                        GameFinished = null,
                        JoinDate     = DateTime.UtcNow,
                        UserId       = Singleton.User().UserId,
                        Active       = true,
                        ImageUrl     = imageUrl,
                        IsBot        = false,
                    });

                    Singleton.CreateGameSession(gameRoom.TeamValue, gameRoom.ProjectValue, gameRoom.MoneyValue,
                                                gameRoom.GameRoomId, playerName, gameRoom.SoftwareType, imageUrl);

                    return(RedirectToAction("WaitRoom", "Room", new { id = gameRoom.GameRoomId }));
                }
                else
                {
                    //Single > start game
                    //Todo Create UserGameRoom and log
                    _service.GameRoom().AddUserGameRoom(new Entity.UserGameRoom
                    {
                        GameRoomId   = gameRoom.GameRoomId,
                        PlayerName   = playerName,
                        JobType      = int.Parse(jobType),
                        MoneyValue   = gameRoom.MoneyValue,
                        ProjectValue = gameRoom.ProjectValue,
                        TeamValue    = gameRoom.TeamValue,
                        GameFinished = null,
                        JoinDate     = DateTime.UtcNow,
                        UserId       = Singleton.User().UserId,
                        Active       = true,
                        TurnValue    = 1,
                        ImageUrl     = imageUrl,
                        IsBot        = false,
                    });

                    if (expertPlayer == true)
                    {
                        //create 2 bot Async
                        _service.BotExpert().CreateBotExpertAsync(gameRoom);
                    }

                    Singleton.CreateGameSession(gameRoom.TeamValue, gameRoom.ProjectValue, gameRoom.MoneyValue,
                                                gameRoom.GameRoomId, playerName, gameRoom.SoftwareType, imageUrl);

                    return(RedirectToAction("Index", "Story", new { id = gameRoom.GameRoomId }));
                }
            }
            return(RedirectToAction("Index", "Home"));
        }
Esempio n. 8
0
        public ActionResult Index()
        {
            if (CommonFunction.CheckCurrentGame() == false)
            {
                return(RedirectToAction("Index", "Home"));
            }

            var gameRoom = _service.GameRoom().GetRoomById(Singleton.Game().GameRoomId);

            //Display all result
            var model = new GameResultViewModel
            {
                MyPlayer = new PlayerData
                {
                    GameBattleId = Singleton.Game().GameBattleId,
                    GameRoomId   = Singleton.Game().GameRoomId,
                    PlayerName   = Singleton.Game().PlayerName,
                    Money        = Singleton.Game().Money.ToString(),
                    Team         = Singleton.Game().Team.ToString(),
                    Project      = Singleton.Game().Project.ToString(),
                    Goal         = Enum.GetName(typeof(Const.GoalType), gameRoom.Goal),
                    GoalStatus   = "",
                    Rank         = "0",
                    GameStatus   = "0",
                },
                GameRoom = new GameRoomModel
                {
                    GameRoomId = gameRoom.GameRoomId
                }
            };

            var friendList   = new List <PlayerData>();
            var userGameRoom = _service.GameRoom().GetCurrentUserGame(Singleton.Game().GameRoomId);

            if (userGameRoom.Count() > 1)
            {
                foreach (var item in userGameRoom.Where(x => x.UserId != Singleton.Game().UserId))
                {
                    friendList.Add(new PlayerData
                    {
                        GameBattleId = Singleton.Game().GameBattleId, // same my player
                        GameRoomId   = item.GameRoomId,
                        PlayerName   = item.PlayerName,
                        Money        = item.MoneyValue.ToString(),
                        Team         = item.TeamValue.ToString(),
                        Project      = item.ProjectValue.ToString(),
                        Rank         = "0",
                        GameStatus   = "0"
                    });
                }
            }

            //set status done
            var done = _service.GameRoom().UpdateGameRoomDone(Singleton.Game().UserId, Singleton.Game().GameRoomId);

            if (done)
            {
                //clear session
                Singleton.ClearGameSession();
            }

            return(View(model));
        }