コード例 #1
0
        public string UpdateFromDb(Func <GameInfoModel, bool> func)
        {
            List <GameInfoModel> list = this.dbContext.GameInfoModel.Where(func).ToList();//item => item.GameStatus != 8

            foreach (GameInfoModel gameInfoModel in list)
            {
                //如果日志不是空的
                if (!string.IsNullOrEmpty(gameInfoModel.loginfo))
                {
                    NewGameViewModel newGameViewModel = new NewGameViewModel()
                    {
                        dropHour = 72, IsAllowLook = gameInfoModel.IsAllowLook, isHall = gameInfoModel.isHall, IsRandomOrder = gameInfoModel.IsRandomOrder, IsRotatoMap = gameInfoModel.IsRotatoMap, IsSocket = false, IsTestGame = gameInfoModel.IsTestGame == 1, jinzhiFaction = gameInfoModel.jinzhiFaction, MapSelction = gameInfoModel.MapSelction, Name = gameInfoModel.name
                    };
                    GameMgr.CreateNewGame(gameInfoModel.userlist.Split('|'), newGameViewModel, out GaiaGame result);
                    // GameMgr.CreateNewGame(gameInfoModel.name, gameInfoModel.userlist.Split('|'), out GaiaGame result, gameInfoModel.MapSelction, isTestGame: gameInfoModel.IsTestGame == 1 ? true : false,version:gameInfoModel.version);
                    GaiaGame gg = GameMgr.GetGameByName(gameInfoModel.name);
                    //gg.dbContext = this.dbContext;
                    gg.GameName = gameInfoModel.name;

                    if (gameInfoModel.saveState == 0)
                    {
                        gg.dbContext  = this.dbContext;
                        gg.IsSaveToDb = true;

                        gameInfoModel.saveState = 1;
                    }


                    gg.UserActionLog = gameInfoModel.loginfo.Replace("|", "\r\n");

                    gg = GameMgr.RestoreGame(gameInfoModel.name, gg);
                    //是否应该结束
                    if (this.FinishGame(gameInfoModel, gg))
                    {
                        this.dbContext.GameInfoModel.Update(gameInfoModel);
                        //没有找到任何的种族信息
                        if (!this.dbContext.GameFactionModel.Any(item => item.gameinfo_id == gameInfoModel.Id))
                        {
                            //保存种族信息
                            DbGameSave.SaveFactionToDb(this.dbContext, gg, gameInfoModel);
                        }
                        else
                        {
                            //总局计分问题,需要重新计算
#if  DEBUG
                            DbGameSave.SaveFactionToDb(this.dbContext, gg, gameInfoModel);
#endif
                        }
                    }

                    //GameMgr.DeleteOneGame(gameInfoModel.name);
                }
            }
            this.dbContext.SaveChanges();
            return("success");
        }
コード例 #2
0
        /// <summary>
        /// 计分
        /// </summary>
        /// <param name="matchInfoModel"></param>
        private void ScoreMatch(MatchInfoModel matchInfoModel)
        {
            //jsonData.data = matchInfoModel;
            matchInfoModel.MatchFinishNumber = 0;
            //分数清零
            //查询当前报名人
            List <MatchJoinModel> matchJoinModels = this.dbContext.MatchJoinModel
                                                    .Where(item => item.matchInfo_id == matchInfoModel.Id).ToList();

            foreach (MatchJoinModel matchJoinModel in matchJoinModels)
            {
                matchJoinModel.Score  = 0;
                matchJoinModel.first  = 0;
                matchJoinModel.second = 0;
                matchJoinModel.third  = 0;
                matchJoinModel.fourth = 0;
                this.dbContext.MatchJoinModel.Update(matchJoinModel);
            }
            //查询当前比赛
            IQueryable <GameInfoModel> gameInfoModels = this.dbContext.GameInfoModel.Where(item => item.matchId == matchInfoModel.Id);

            //遍历比赛
            foreach (GameInfoModel gameInfoModel in gameInfoModels)
            {
                bool isFinish = DbGameSave.SaveMatchToDb(gameInfoModel, dbContext);
                if (isFinish)
                {
                    matchInfoModel.MatchFinishNumber++;
                }
            }

            //如果7场全部结束,更新冠军
            int gameCount = gameInfoModels.Count();

            //如果结束场次是现有场次
            if (matchInfoModel.MatchFinishNumber == gameCount)
            {
                //查询分数最高的
                IQueryable <MatchJoinModel> match = this.dbContext.MatchJoinModel.Where(item => item.matchInfo_id == matchInfoModel.Id).OrderByDescending(item => item.Score);
                String username = match.ToList()[0].username;
                matchInfoModel.Champion = username;
                //进行中1变结束2
                matchInfoModel.State = 2;

                //matchInfoModel.MatchFinishNumber = (short) gameCount;
                //结束时间
                matchInfoModel.EndTime = DateTime.Now;
                //matchInfoModel.MatchTotalNumber = (short)gameCount;
            }
            this.dbContext.MatchInfoModel.Update(matchInfoModel);
        }
コード例 #3
0
        /// <summary>
        /// 从内存更新游戏
        /// </summary>
        /// <returns></returns>
        public IActionResult UpdateGame()
        {
            var list = GameMgr.GetAllGame();

            foreach (KeyValuePair <string, GaiaGame> keyValuePair in list)
            {
                var result = keyValuePair.Value;

                GaiaDbContext.Models.HomeViewModels.GameInfoModel gameInfoModel;
                var listG = this.dbContext.GameInfoModel.Where(item => item.name == keyValuePair.Key).OrderByDescending(item => item.starttime).ToList();
                if (listG.Count > 0)
                {
                    gameInfoModel = listG[0];
                }
                else
                {
                    continue;
                }
                //如果不存在
                bool isExist = true;
                if (gameInfoModel == null)
                {
                    //测试游戏跳过
                    if (result.IsTestGame)
                    {
                        continue;
                    }
                    isExist       = false;
                    gameInfoModel =
                        new GaiaDbContext.Models.HomeViewModels.GameInfoModel()
                    {
                        name        = keyValuePair.Key,
                        userlist    = string.Join("|", result.Username),
                        UserCount   = result.Username.Length,
                        MapSelction = keyValuePair.Value.MapSelection.ToString(),
                        IsTestGame  = keyValuePair.Value.IsTestGame ? 1 : 0,
                        GameStatus  = 0,
                        starttime   = DateTime.Now,
                        endtime     = DateTime.Now,
                        round       = 0,

                        //username = HttpContext.User.Identity.Name,
                    };
                    this.FinishGame(gameInfoModel, result);
                }
                else
                {
                    //结束的游戏不需要更新
                    if (gameInfoModel.GameStatus == 8)
                    {
                        continue;
                    }
                    else
                    {
                        gameInfoModel.round = result.GameStatus.RoundCount;
                        //如果游戏结束
                        if (this.FinishGame(gameInfoModel, result))
                        {
                            //并且没有找到任何的种族信息
                            if (!this.dbContext.GameFactionModel.Any(item => item.gameinfo_id == gameInfoModel.Id))
                            {
                                //保存种族信息
                                DbGameSave.SaveFactionToDb(this.dbContext, result, gameInfoModel);
                            }
                        }
                    }
                }

                gameInfoModel.ATTList  = string.Join("|", result.ATTList.Select(item => item.name));
                gameInfoModel.FSTList  = string.Join("|", result.FSTList.Select(item => item.GetType().Name));
                gameInfoModel.RBTList  = string.Join("|", result.RBTList.Select(item => item.name));
                gameInfoModel.RSTList  = string.Join("|", result.RSTList.Select(item => item.GetType().Name));
                gameInfoModel.STT3List = string.Join("|",
                                                     result.STT3List.GroupBy(item => item.name).Select(g => g.Max(item => item.name)));
                gameInfoModel.STT6List = string.Join("|",
                                                     result.STT6List.GroupBy(item => item.name).Select(g => g.Max(item => item.name)));
                gameInfoModel.scoreFaction =
                    string.Join(":",
                                result.FactionList.OrderByDescending(item => item.Score)
                                .Select(item => string.Format("{0}{1}({2})", item.ChineseName,
                                                              item.Score, item.UserName))); //最后的得分情况
                gameInfoModel.loginfo = string.Join("|", result.LogEntityList.Select(item => item.Syntax));

                if (isExist)
                {
                    this.dbContext.GameInfoModel.Update(gameInfoModel);
                }
                else
                {
                    this.dbContext.GameInfoModel.Add(gameInfoModel);
                }
            }
            this.dbContext.SaveChanges();

            return(Redirect("/GameInfo/Index?status=0"));
        }