Example #1
0
        public ActionResult ProtectRisk(FormCollection form)
        {
            var selectedRisk = form.AllKeys.Where(x => x.Contains("RiskId")).ToList();
            var moneySummary = 0;

            if (selectedRisk.Any())
            {
                foreach (var item in selectedRisk)
                {
                    var optionId   = int.Parse(form[item]);
                    var riskOption = _service.Risk().GetRiskOptionById(optionId, 1);

                    if (riskOption != null)
                    {
                        moneySummary += riskOption.ActionEffectValue.GetValueOrDefault();

                        _service.Game().AddUserGameRisk(new UserGameRisk
                        {
                            UserId       = Singleton.User().UserId,
                            Turn         = Singleton.Game().Turn,
                            GameRoomId   = Singleton.Game().GameRoomId,
                            RiskOptionId = optionId,
                            RiskId       = riskOption.RiskId.GetValueOrDefault(),
                            CreateDate   = DateTime.UtcNow,
                            CreateBy     = Singleton.User().UserId
                        });
                    }
                    //save database
                }
            }

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

            if (gameRoom.IncludeBot.GetValueOrDefault() == true)
            {
                var botTurn       = Singleton.Game().Turn;
                var botGameRoomId = gameRoom.GameRoomId;
                _service.BotExpert().BotProtectRiskAsync(botGameRoomId, botTurn, (int)JobType.ExpertSpecialist);
                _service.BotExpert().BotProtectRiskAsync(botGameRoomId, botTurn, (int)JobType.Newbies);
            }
            //if (gameRoom != null)
            //{
            //    gameRoom.MoneyValue = Singleton.Game().Money - moneySummary;
            //}
            var money = Singleton.Game().Money - moneySummary;

            _service.GameRoom().UpdateUserGameRoom(Singleton.Game().UserId, Singleton.Game().GameRoomId, money, Singleton.Game().Turn);
            Singleton.UpdateGameSession(Singleton.Game().Team, Singleton.Game().Project, money, Singleton.Game().Turn, Singleton.Game().SoftwareType, Singleton.Game().PlayerImageUrl);
            return(RedirectToAction("OpenRisk", "Game"));
        }
Example #2
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"));
        }