Example #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");
        }
Example #2
0
        /// <summary>
        /// 创建游戏,从内存
        /// </summary>
        private GaiaGame CreateGame(string[] username, NewGameViewModel model, out GaiaGame result)
        {
            //删除空白玩家
            username = username.Where(x => !string.IsNullOrEmpty(x)).ToArray();

            //随机排序
            if (model.IsRandomOrder)
            {
                username = this.RandomSortList <string>(username).ToArray();
            }


            //创建游戏
            bool create = GameMgr.CreateNewGame(username, model, out result, _userManager: _userManager);


            if (!string.IsNullOrEmpty(model.jinzhiFaction))
            {
                var list = new List <Faction>()
                {
                    new Terraner(null),
                    new Lantida(null),
                    new Hive(null),
                    new HadschHalla(null),
                    new BalTak(null),
                    new Geoden(null),
                    new Gleen(null),
                    new Xenos(null),
                    new Ambas(null),
                    new Taklons(null),
                    new Firaks(null),
                    new MadAndroid(null),
                    new Itar(null),
                    new Nevla(null)
                };
                result.JinzhiFaction = new List <Faction>();
                foreach (string name in model.jinzhiFaction.Split(','))
                {
                    result.JinzhiFaction.Add(list.Find(fac => fac.FactionName.ToString() == name));
                }
            }
            return(result);
        }
Example #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="id">游戏ID</param>
        /// <param name="type"></param>
        /// <returns></returns>
        private GaiaGame RestoreGame(int id, out int type, int?row = null)
        {
            //游戏结果
            GameInfoModel gameInfoModel = this.dbContext.GameInfoModel.SingleOrDefault(item => item.Id == id);

            if (gameInfoModel != null)
            {
                gameInfoModel.userlist = gameInfoModel.userlist.Trim('|');
                string log;
                //游戏已经结束
                if (gameInfoModel.GameStatus == 8)
                {
                    log = gameInfoModel.loginfo;
                }
                else if (!gameInfoModel.IsAllowLook)//不允许查看
                {
                    type = 0;
                    return(null);
                }
                else
                {
                    var game = GameMgr.GetGameByName(gameInfoModel.name);
                    if (game == null)//游戏不存在
                    {
                        if (string.IsNullOrEmpty(gameInfoModel.loginfo))
                        {
                            type = 0;
                            return(null);
                        }
                        log = gameInfoModel.loginfo;
                    }
                    else
                    {
                        type = 1;//跳转
                        return(game);
                        //return Redirect("/Home/ViewGame/" + gameInfoModel.name);
                    }
                    //log = game.UserActionLog;
                }

                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,IsRotatoMap:gameInfoModel.IsRotatoMap,version:gameInfoModel.version);
                GaiaGame gg = GameMgr.GetGameByName(gameInfoModel.name);
                gg.GameName      = gameInfoModel.name;
                gg.UserActionLog = log?.Replace("|", "\r\n");

                //赋值会重写全部数据
                gg.dbContext = this.dbContext;

                gg          = GameMgr.RestoreGame(gameInfoModel.name, gg, row: row);
                gg.GameName = gameInfoModel.name;
                //从内存删除
                GameMgr.DeleteOneGame(gameInfoModel.name);
                type = 200;
                return(gg);
            }
            type = 0;
            return(null);
        }
        /// <summary>
        /// 自动创建比赛
        /// </summary>
        private void AutoCreateMatch(MatchInfoModel matchInfoModel)
        {
            //是否自动创建比赛
            //并且只能创建7人的比赛
            if (matchInfoModel.IsAutoCreate && matchInfoModel.NumberNow == matchInfoModel.NumberMax && matchInfoModel.NumberNow == 7)
            {
                //取出全部的报名人员
                List <MatchJoinModel> matchJoinModels = this.dbContext.MatchJoinModel.Where(item => item.matchInfo_id == matchInfoModel.Id).ToList();

                if (matchJoinModels.Count() == 7)
                {
                    //int[7][4] rank = new int();

                    int[,] userOrder = new int[7, 4] {
                        { 1, 5, 4, 3 }, { 5, 2, 6, 1 }, { 2, 4, 0, 5 }, { 4, 6, 3, 2 }, { 6, 0, 1, 4 }, { 0, 3, 5, 6 }, { 3, 1, 2, 0 }
                    };

                    //创建游戏
                    NewGameViewModel newGameViewModel = new NewGameViewModel()
                    {
                        dropHour      = 72,
                        IsAllowLook   = true,
                        isHall        = false,
                        IsRandomOrder = false,
                        IsRotatoMap   = true,
                        IsSocket      = false,
                        IsTestGame    = false,
                        jinzhiFaction = null,
                        MapSelction   = GameInfoAttribute.MapSelction[GameInfoAttribute.MapSelction.Count - 1].code,
                        //Name = matchInfoModel.GameName,
                    };

                    for (int i = 0; i < 7; i++)
                    {
                        string[] users = new string[]
                        {
                            matchJoinModels[userOrder[i, 0]].username, matchJoinModels[userOrder[i, 1]].username, matchJoinModels[userOrder[i, 2]].username, matchJoinModels[userOrder[i, 3]].username
                        };
                        //游戏名称
                        if (matchInfoModel.GameName.Contains("{0}"))
                        {
                            newGameViewModel.Name = string.Format(matchInfoModel.GameName, i + 1);
                        }
                        else
                        {
                            newGameViewModel.Name = string.Concat(matchInfoModel.GameName, i + 1);
                        }
                        //创建游戏到内存
                        GameMgr.CreateNewGame(users, newGameViewModel, out GaiaGame gaiaGame, _userManager: _userManager);
                        //保存到数据库
                        GameMgr.SaveGameToDb(newGameViewModel, "gaia", null, this.dbContext, gaiaGame, matchId: matchInfoModel.Id, userlist: users);
                    }
                }
                //将游戏标准为进行状态
                matchInfoModel.State = 1;
                //比赛场次
                matchInfoModel.MatchTotalNumber = 7;
                //开始时间
                matchInfoModel.StartTime = DateTime.Now;

                this.dbContext.MatchInfoModel.Update(matchInfoModel);
                this.dbContext.SaveChanges();
            }
        }