コード例 #1
0
        /// <summary>
        /// 玩家的平均分
        /// </summary>
        public IActionResult UserScoreAvg(GameFactionModel gameFactionModel, int?orderType, int usercount = 4)
        {
            IQueryable <GameFactionModel> query;

            //90一下的不纳入统计
            query = this.dbContext.GameFactionModel.Where(item => item.scoreTotal > 90);
            //人数
            if (usercount > 0)
            {
                query = query.Where(item => item.UserCount == usercount);
            }
            //查询种族
            if (gameFactionModel.FactionName != null)
            {
                query = query.Where(item => item.FactionName == gameFactionModel.FactionName);
            }


            var list = query.GroupBy(item => item.username).Select(
                g => new Models.Data.GameInfoController.StatisticsFaction()
            {
                ChineseName    = g.Key,
                count          = g.Count(),
                numberwin      = g.Count(faction => faction.rank == 1),
                winprobability = g.Count(faction => faction.rank == 1) * 100 / (g.Count()),
                scoremin       = g.Min(faction => faction.scoreTotal),
                scoremax       = g.Max(faction => faction.scoreTotal),
                scoremaxuser   = g.OrderByDescending(faction => faction.scoreTotal).ToList()[0].username,
                scoreavg       = g.Sum(faction => faction.scoreTotal) / g.Count(),
            });

            //场次要大于3场
            list = list.Where(item => item.count > 2);
            //排序方式
            if (orderType != null)
            {
                switch (orderType)
                {
                case 1:
                    list = list.OrderByDescending(item => item.count);
                    break;

                case 2:
                    list = list.OrderByDescending(item => item.scoreavg);
                    break;

                case 3:
                    list = list.OrderByDescending(item => item.numberwin);
                    break;

                case 4:
                    list = list.OrderByDescending(item => item.winprobability);
                    break;
                }
            }
            else
            {
                list = list.OrderByDescending(item => item.count);
            }
            return(View(list.ToList()));
        }
コード例 #2
0
        /// <summary>
        /// 保存种族信息到数据库
        /// </summary>
        /// <param name="dbContext"></param>
        /// <param name="gaiaGame"></param>
        /// <param name="gameInfoModel"></param>
        public static void SaveFactionToDb(ApplicationDbContext dbContext, GaiaGame gaiaGame, GameInfoModel gameInfoModel)
        {
            //再保存玩家信息
            Func <Faction, int, int> getscore = (faction, index) =>
            {
                faction.FinalEndScore = 0;
                gaiaGame.FSTList[index].InvokeGameTileAction(gaiaGame.FactionList);
                return(faction.FinalEndScore);
            };
            //排名
            int rankindex   = 1;
            var factionList = gaiaGame.FactionList.OrderByDescending(f => f.Score).ToList();

            //如果第一名小于100
            if (factionList[0].Score < 100)
            {
            }
            //最高分
            int scoreMax = 0;
            List <GameFactionModel> gameFactionModels = new List <GameFactionModel>(factionList.Count);

            foreach (Faction faction in factionList)
            {
                GameFactionModel gameFactionModel = dbContext.GameFactionModel.SingleOrDefault(
                    item => item.gameinfo_id == gameInfoModel.Id && item.FactionName == faction.FactionName.ToString());
                //没有就新建
                bool isAdd = true;
                if (gameFactionModel == null)
                {
                    gameFactionModel = new GaiaDbContext.Models.HomeViewModels.GameFactionModel()
                    {
                        gameinfo_id        = gameInfoModel.Id,
                        gameinfo_name      = gaiaGame.GameName,
                        FactionName        = faction.FactionName.ToString(),
                        FactionChineseName = faction.ChineseName,
                    };
                    gameFactionModel.userid     = null;
                    gameFactionModel.username   = faction.UserName;
                    gameFactionModel.scoreRound = null;
                    gameFactionModel.scorePw    = 0;
                    //玩家人数
                    gameFactionModel.UserCount = gameInfoModel.UserCount;
                }
                else
                {
                    isAdd = false;
                }
                //修改属性
                gameFactionModel.kjPostion = string.Join("|", faction.TransformLevel, faction.ShipLevel,
                                                         faction.AILevel, faction.GaiaLevel, faction.EconomicLevel,
                                                         faction.ScienceLevel);
                gameFactionModel.numberBuild = string.Join("|", 8 - faction.Mines.Count,
                                                           4 - faction.TradeCenters.Count, 3 - faction.ResearchLabs.Count,
                                                           faction.Academy1 == null ? 1 : 0, faction.Academy2 == null ? 1 : 0,
                                                           faction.StrongHold == null ? 1 : 0);
                gameFactionModel.numberFst1 = gaiaGame.FSTList[0].TargetNumber(faction);
                gameFactionModel.numberFst2 = gaiaGame.FSTList[1].TargetNumber(faction);
                gameFactionModel.scoreFst1  = getscore(faction, 0);
                gameFactionModel.scoreFst2  = getscore(faction, 1);
                gameFactionModel.scoreKj    = faction.GetTechScoreCount() * 4;
                gameFactionModel.scoreTotal = faction.Score;
                //记录最高分
                if (rankindex == 1)
                {
                    scoreMax = gameFactionModel.scoreTotal;
                }
                //如果是后面的玩家并且与上一名玩家分数相同
                if (rankindex > 1 && gameFactionModel.scoreTotal == factionList[rankindex - 2].Score)
                {
                    gameFactionModel.rank = gameFactionModels[rankindex - 2].rank;
                    //gameFactionModel.rank = dbContext.GameFactionModel.SingleOrDefault(item => item.gameinfo_id == gameInfoModel.Id && item.FactionName == factionList[rankindex - 2].FactionName.ToString()).rank;//排名
                }
                else
                {
                    gameFactionModel.rank = rankindex;//排名
                    //faction.
                }
                //计算裸分
                gameFactionModel.scoreLuo = gameFactionModel.scoreTotal - gameFactionModel.scoreFst1 -
                                            gameFactionModel.scoreFst2 - gameFactionModel.scoreKj;
                //计算分差
                gameFactionModel.scoreDifference = scoreMax - gameFactionModel.scoreTotal;
                //添加到数组
                gameFactionModels.Add(gameFactionModel);

                if (isAdd)
                {
                    //检查玩家是否drop,存库
                    try
                    {
                        if (faction.dropType > 0)
                        {
                            ApplicationUser singleOrDefault = dbContext.Users.SingleOrDefault(user => user.UserName == faction.UserName);
                            if (singleOrDefault != null)
                            {
                                singleOrDefault.droptimes++;
                                dbContext.Users.Update(singleOrDefault);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                    }
                    //保存种族信息
                    dbContext.GameFactionModel.Add(gameFactionModel);
                }
                else
                {
                    dbContext.GameFactionModel.Update(gameFactionModel);
                }


                rankindex++;
            }
        }
コード例 #3
0
        /// <summary>
        /// 个人使用的种族信息
        /// </summary>
        /// <returns></returns>
        public IActionResult FactionList(GameFactionModel gameFactionModel, int?type, int?usercount, int orderType = 1, int pageindex = 1)
        {
            //gameFactionModel.UserCount
            if (gameFactionModel.username == null)
            {
                gameFactionModel.username = HttpContext.User.Identity.Name;
            }
            IQueryable <GameFactionModel> gameFactionModels;

            if (type == 1)//全部
            {
                gameFactionModels = this.dbContext.GameFactionModel.AsQueryable();
            }
            else if (type == 2)//高分
            {
                gameFactionModels = this.dbContext.GameFactionModel.AsQueryable();
            }
            else//自己的
            {
                gameFactionModels = this.dbContext.GameFactionModel.Where(item => item.username == gameFactionModel.username);
            }

            //种族
            if (gameFactionModel.FactionName != null)
            {
                gameFactionModels = gameFactionModels.Where(item => item.FactionName == gameFactionModel.FactionName);
            }

            //人数
            usercount = usercount ?? 4;
            if (usercount > 0)
            {
                gameFactionModels = gameFactionModels.Where(item => item.UserCount == usercount);
            }
            List <Models.Data.GameInfoController.StatisticsFaction> list = null;

            //不是高分统计
            if (type != 2)
            {
                if (gameFactionModels.Any())
                {
                    //种族统计和平均分
                    list = this.GetFactionStatistics(gameFactionModels, usercount, HttpContext.User.Identity.Name);
                    //全部的平均分
                    Models.Data.GameInfoController.StatisticsFaction allavg = gameFactionModels
                                                                              .GroupBy(item => item.username).Select(
                        g => new Models.Data.GameInfoController.StatisticsFaction()
                    {
                        ChineseName    = "全部",
                        count          = g.Count(),
                        numberwin      = g.Count(faction => faction.rank == 1),
                        winprobability = g.Count(faction => faction.rank == 1) * 100 / (g.Count()),
                        scoremin       = g.Min(faction => faction.scoreTotal),
                        scoremax       = g.Max(faction => faction.scoreTotal),
                        scoremaxuser   = g.OrderByDescending(faction => faction.scoreTotal).ToList()[0].username,
                        scoreavg       = g.Sum(faction => faction.scoreTotal) / g.Count(),
                        OccurrenceRate = 100,
                    })?.ToList()[0];
                    list.Add(allavg);
                }
            }

            //list = list.OrderByDescending(item => item.starttime).Skip(30 * (pageindex - 1)).Take(30);


            if (type == null)
            {
                //时间
                if (orderType == 1)
                {
                    gameFactionModels = gameFactionModels.OrderByDescending(item => item.Id).Skip(30 * (pageindex - 1)).Take(30);
                }
                else if (orderType == 2)//总分
                {
                    gameFactionModels = gameFactionModels.OrderByDescending(item => item.scoreTotal).Skip(30 * (pageindex - 1)).Take(30);
                }
                else if (orderType == 3)//裸分
                {
                    gameFactionModels = gameFactionModels.OrderByDescending(item => item.scoreLuo).Skip(30 * (pageindex - 1)).Take(30);
                }
            }
            else
            {
                //前30条
                if (type != 1)
                {
                    gameFactionModels = gameFactionModels.OrderByDescending(item => item.scoreTotal).Skip(30 * (pageindex - 1)).Take(30);
                }
                else
                {
                    gameFactionModels = gameFactionModels.OrderByDescending(item => item.scoreTotal);
                }
            }

            //赋值model
            FactionListInfo factionListInfo = new FactionListInfo();

            factionListInfo.ListGameFaction       = gameFactionModels.ToList();
            factionListInfo.ListStatisticsFaction = list ?? new List <Models.Data.GameInfoController.StatisticsFaction>();
            //gameFactionModels = gameFactionModels.OrderByDescending(item => item.scoreTotal);
            return(View(factionListInfo));
        }