Exemplo n.º 1
0
        public async Task <JsonResult> DelGame(int id)
        {
            Models.Data.UserFriendController.JsonData jsonData = new Models.Data.UserFriendController.JsonData();
            var user = await _userManager.GetUserAsync(HttpContext.User);

            if (user != null)
            {
                GameInfoModel gameInfoModel = this.dbContext.GameInfoModel.SingleOrDefault(item => item.Id == id);
                if (gameInfoModel != null)
                {
                    GaiaGame gaiaGame = GameMgr.GetGameByName(gameInfoModel.name);
                    foreach (string username in gaiaGame.Username)
                    {
                        //如果不是自己
                        if (username != user.UserName)
                        {
                            this.dbContext.GameDeleteModel.Add(new GameDeleteModel()
                            {
                                gameinfo_id   = gameInfoModel.Id,
                                gameinfo_name = gameInfoModel.name,
                                username      = username,
                                state         = 0,
                            });
                        }
                    }
                    gameInfoModel.isDelete = 1;
                    this.dbContext.SaveChanges();
                    jsonData.info.state = 200;
                }
            }
            return(new JsonResult(jsonData));
        }
Exemplo n.º 2
0
    public void UpdateRankList()
    {
        //遍历获取XML
        List <GameInfoModel> list = base.VCLoadXMLManage();
        //当前分数
        int nowScore = (int)FindObjectOfType <GameController>().score;
        //添加当前分数信息
        var mod = new GameInfoModel {
            Id    = FindObjectOfType <GameController>().playerID,
            Score = nowScore,
            Time  = FindObjectOfType <GameController>().surviveTime
        };

        list.Add(mod);
        //倒序
        list = list.OrderByDescending(p => p.Score).ThenBy(p => p.Time).ToList();
        //删除最后一个最少的
        if (list.Count > 5)
        {
            list.RemoveAt(list.Count - 1);
        }

        base.VCRemoveXmlElement();
        base.VCAddXml(list);
    }
Exemplo n.º 3
0
        public ScrapeArt(string title)
        {
            var order = new[] {
                Settings.Default.APIUserSequence,
                Settings.Default.APIAutoSequence
            }
            .First(p => string.IsNullOrEmpty(p) == false)
            .Split(',')
            .Select(int.Parse)
            .ToArray();

            Scrapers = Scrapers
                       .Select((p, i) => i)
                       .ToDictionary(
                p => order[p],
                p => Scrapers[order[p]]
                );

            var scraperOrder = Scrapers
                               .OrderBy(p => ApiPerformanceStats.ContainsKey(p.Key) ? ApiPerformanceStats[p.Key].Failures : 100)
                               .ThenBy(p => ApiPerformanceStats.ContainsKey(p.Key) ? ApiPerformanceStats[p.Key].AverageMs : 100)
                               .ToArray();

            Settings.Default.APIAutoSequence = string.Join(",", scraperOrder.Select(p => p.Key));
            Settings.Default.Save();

            foreach (var scraper in scraperOrder)
            {
                if (ApiPerformanceStats.ContainsKey(scraper.Key) == false)
                {
                    ApiPerformanceStats[scraper.Key] = new PerformanceStat();
                }

                var stopwatch = new Stopwatch();
                stopwatch.Start();
                Result = scraper.Value.GetDataFromApi(title);
                if (Result?.ThumbnailUrl == null)
                {
                    stopwatch.Stop();
                    ApiPerformanceStats[scraper.Key].Milliseconds.Add(stopwatch.ElapsedMilliseconds);
                    ApiPerformanceStats[scraper.Key].Failures++;
                    continue;
                }

                var downloadSuccess = SaveImageFromUrl(title, Result.ThumbnailUrl);
                if (downloadSuccess == false)
                {
                    stopwatch.Stop();
                    ApiPerformanceStats[scraper.Key].Milliseconds.Add(stopwatch.ElapsedMilliseconds);
                    ApiPerformanceStats[scraper.Key].Failures++;
                    continue;
                }
                stopwatch.Stop();
                ApiPerformanceStats[scraper.Key].Milliseconds.Add(stopwatch.ElapsedMilliseconds);
                return;
            }

            Console.WriteLine("All APIs failed");
        }
Exemplo n.º 4
0
        public void DoGame()
        {
            Output.ShowSomeOutput(TextCuts.StartGame);
            Output.ShowSomeOutput(TextCuts.EnterName);

            GameService  gameService  = new GameService();
            RoundService roundService = new RoundService();

            string userName = Input.InputString();

            Output.ShowSomeOutput(TextCuts.HowManyBots, Settings.MaxBots);
            int howManyBots = Input.InputInt(Settings.MinBots, Settings.MaxBots);

            Output.ShowSomeOutput(TextCuts.EnterValidRate, Settings.MinRateForGamer, Settings.MaxRateForGamer);
            int rate = Input.InputInt(Settings.MinRateForGamer, Settings.MaxRateForGamer);

            Output.ShowSomeOutput(TextCuts.ShowStartRaund);

            var GameInfo = new GameInfoModel
            {
                UserName    = userName,
                UserRate    = rate,
                HowManyBots = howManyBots
            };

            GamerView gamer = gameService.PrepareGame(GameInfo);

            Output.ShowAllGamerCards(gamer);
            Output.ShowSomeOutput(TextCuts.NowYouHave + gamer.Points);

            bool   isAnswer = true;
            string gamerAnswer;

            while (isAnswer)
            {
                Output.ShowSomeOutput(TextCuts.DoYouWantCard);
                gamerAnswer = Input.InputString();
                if (gamerAnswer == Settings.YesAnswer && gamer.Status != GamerViewStatus.Enough)
                {
                    gamer = roundService.GiveCardToTheRealPlayer();
                    Output.ShowAllGamerCards(gamer);
                    Output.ShowSomeOutput(TextCuts.NowYouHave + gamer.Points);
                }
                if (gamerAnswer != Settings.YesAnswer || gamer.Status == GamerViewStatus.Many)
                {
                    isAnswer = false;
                    gameService.GamerSayEnaugh();
                }
            }

            List <GamerView> finalResult = roundService.DoRoundForAllGamerWithResult();

            Output.ShowFinishResult(finalResult);
            gameService.WriteHistoryInFile();

            Console.ReadKey();
        }
 public ActionResult Index()
 {
     try
     {
         GameInfoModel gameStateModel = new GameInfoModel(Game);
         return(Json(gameStateModel));
     }
     catch (Exception ex)
     {
         return(StatusCode(500, ex));
     }
 }
 private static GameInfo GameInfoTO(GameInfoModel gameInfoModel)
 => new GameInfo
 {
     Description = gameInfoModel.Description,
     Developer   = gameInfoModel.Developer,
     Genre       = gameInfoModel.Genre,
     Language    = gameInfoModel.Language,
     Name        = gameInfoModel.Name,
     Platform    = gameInfoModel.Platform,
     Rate        = gameInfoModel.Rate,
     Release     = gameInfoModel.Release
 };
Exemplo n.º 7
0
        public async Task <JsonResult> JoinGame(int id)
        {
            Models.Data.UserFriendController.JsonData jsonData = new Models.Data.UserFriendController.JsonData();

            GameInfoModel gameInfoModel = this.dbContext.GameInfoModel.SingleOrDefault(item => item.Id == id);

            if (gameInfoModel != null)
            {
                //如果包括自己
                if (this.User.Identity.Name == null)
                {
                    jsonData.info.state   = 400;
                    jsonData.info.message = "没有登陆";
                }
                else if (gameInfoModel.userlist.Contains(string.Format("|{0}|", this.User.Identity.Name)))
                {
                    jsonData.info.state   = 400;
                    jsonData.info.message = "已经加入";
                }
                else
                {
                    gameInfoModel.userlist = gameInfoModel.userlist + this.User.Identity.Name + "|";

                    //判断是否满足人数,正式开始游戏
                    string[] username = gameInfoModel.userlist.Trim('|').Split('|');
                    if (username.Length == gameInfoModel.UserCount)
                    {
                        gameInfoModel.round = 0;
                        NewGameViewModel newGameViewModel = new NewGameViewModel()
                        {
                            IsAllowLook   = gameInfoModel.IsAllowLook,
                            IsRandomOrder = gameInfoModel.IsRandomOrder,
                            IsRotatoMap   = gameInfoModel.IsRotatoMap,
                            IsTestGame    = gameInfoModel.IsTestGame == 1,
                            MapSelction   = gameInfoModel.MapSelction,
                            Name          = gameInfoModel.name,
                            jinzhiFaction = gameInfoModel.jinzhiFaction,
                        };
                        //创建游戏
                        GaiaGame gaiaGame;
                        this.CreateGame(username, newGameViewModel, out gaiaGame);
                    }
                    this.dbContext.GameInfoModel.Update(gameInfoModel);
                    this.dbContext.SaveChanges();

                    jsonData.info.state   = 200;
                    jsonData.info.message = "成功";
                }
            }

            return(new JsonResult(jsonData));
        }
Exemplo n.º 8
0
        public async Task <JsonResult> AgreeDelGame(int id, int type)
        {
            Models.Data.UserFriendController.JsonData jsonData = new Models.Data.UserFriendController.JsonData();
            GameDeleteModel gameDeleteModel = this.dbContext.GameDeleteModel.SingleOrDefault(
                item => item.Id == id && item.username == User.Identity.Name);

            if (gameDeleteModel != null)
            {
                GameInfoModel gameInfoModel = this.dbContext.GameInfoModel.SingleOrDefault(item => item.Id == gameDeleteModel.gameinfo_id);
                //申请删除状态
                if (gameInfoModel.isDelete == 1)
                {
                    {
                        //同意删除
                        if (type == 1)
                        {
                            //删除同意记录
                            this.dbContext.GameDeleteModel.Remove(gameDeleteModel);
                            this.dbContext.SaveChanges();
                            //如果是最后一个同意的,则删除游戏
                            if (!this.dbContext.GameDeleteModel.Any(item => item.gameinfo_id == gameDeleteModel.gameinfo_id))
                            {
                                this.DeleteDbGame(gameDeleteModel.gameinfo_id);
                                jsonData.info.message = "全部玩家同意删除,已删除游戏";
                            }
                            else
                            {
                                jsonData.info.message = "继续等待其他玩家处理删除申请";
                            }
                        }
                        else//不同意删除
                        {
                            //移除全部的申请
                            this.dbContext.GameDeleteModel.RemoveRange(this.dbContext.GameDeleteModel.Where(item => item.gameinfo_id == gameDeleteModel.gameinfo_id));
                            //申请删除游戏恢复
                            GameInfoModel infoModel = this.dbContext.GameInfoModel.SingleOrDefault(item => item.Id == gameDeleteModel.gameinfo_id);
                            if (infoModel != null)
                            {
                                infoModel.isDelete = 0;
                                this.dbContext.GameInfoModel.Update(infoModel);
                                jsonData.info.message = "游戏已经恢复正常状态";
                            }
                        }
                        this.dbContext.SaveChanges();
                    }
                    jsonData.info.state = 200;
                }
            }

            return(new JsonResult(jsonData));
        }
        private void Save()
        {
            var gameinfo = new GameInfoModel
            {
                FileName = Path.GetFileName(NewGameFileName),
                GameType = NewGameGameType.Extension,
                Name     = NewGameName,
                Players  = NewGamePlayers.ToArray()
            };
            var jsonObject = JsonConvert.SerializeObject(gameinfo);

            File.WriteAllText($"{_mainViewModel.DataDirectory}\\{NewGameName}.json", jsonObject);
            _mainViewModel.AddedNewGame();
        }
Exemplo n.º 10
0
        /// <summary>
        /// 删除游戏
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>

        public bool DeleteOneGame(string id)
        {
            if (!PowerUser.IsPowerUser(User.Identity.Name))
            {
                return(false);
            }
            //数据库一起删除
            GameInfoModel gameInfoModel = this.dbContext.GameInfoModel.SingleOrDefault(item => item.name == id);

            if (gameInfoModel != null)
            {
                this.dbContext.GameInfoModel.Remove(gameInfoModel);
                this.dbContext.SaveChanges();
            }
            return(GameMgr.DeleteOneGame(id));
        }
Exemplo n.º 11
0
        public GamerView PrepareGame(GameInfoModel gameInfo)
        {
            StaticGamerList.StaticGamersList = GenerateBotList(StaticGamerList.StaticGamersList, gameInfo.HowManyBots, Settings.BotName);
            StaticGamerList.StaticGamersList = AddPlayer(StaticGamerList.StaticGamersList, gameInfo.UserName, gameInfo.UserRate, GamerRole.Gamer, GamerStatus.Plays);
            StaticGamerList.StaticGamersList = AddPlayer(StaticGamerList.StaticGamersList, Settings.DealerName, Settings.DealerRate, GamerRole.Dealer, GamerStatus.Plays);
            StaticCardList.StaticCardsList   = CardDeckService.DoOneDeck();
            RoundService round = new RoundService();

            StaticGamerList.StaticGamersList = round.DoFirstRound(StaticGamerList.StaticGamersList, StaticCardList.StaticCardsList, Settings.HowManyCardsInFirstRound);

            List <GamerView> outputGamerViewList = GetGamerViewList(StaticGamerList.StaticGamersList);

            GamerView gamer = GamerFromViewList(outputGamerViewList);

            return(gamer);
        }
Exemplo n.º 12
0
        public static bool SaveMatchToDb(GameInfoModel gameInfoModel, ApplicationDbContext dbContext)
        {
            //计分
            Int16[] points = new Int16[] { 6, 3, 1, 0 };

            //如果已经结束,则标记计分
            if (gameInfoModel.round != 7)
            {
                return(false);
                //continue; ;
            }
            //玩家情况
            List <GameFactionModel> gameFactionModels = dbContext.GameFactionModel.Where(item => item.gameinfo_id == gameInfoModel.Id).OrderByDescending(item => item.scoreTotal).ToList();

            //玩家依次加分
            for (int i = 0; i < 4; i++)
            {
                MatchJoinModel matchJoinModel = dbContext.MatchJoinModel.SingleOrDefault(item => item.matchInfo_id ==
                                                                                         gameInfoModel.matchId && item.username == gameFactionModels[i].username);
                if (matchJoinModel == null)
                {
                    continue;
                }
                switch (i)
                {
                case 0:
                    matchJoinModel.first++;
                    break;

                case 1:
                    matchJoinModel.second++;
                    break;

                case 2:
                    matchJoinModel.third++;
                    break;

                case 3:
                    matchJoinModel.fourth++;
                    break;
                }
                matchJoinModel.Score += points[i];
                //玩家信息保存
                dbContext.MatchJoinModel.Update(matchJoinModel);
            }
            return(true);
        }
Exemplo n.º 13
0
        public async Task <JsonResult> ExitGame(int id)
        {
            Models.Data.UserFriendController.JsonData jsonData = new Models.Data.UserFriendController.JsonData();
            GameInfoModel gameInfoModel = this.dbContext.GameInfoModel.SingleOrDefault(item => item.Id == id);

            if (gameInfoModel != null)
            {
                string username = this.User.Identity.Name;
                //如果不包括自己
                if (!gameInfoModel.userlist.Contains(username))
                {
                    jsonData.info.state   = 400;
                    jsonData.info.message = "没有加入,无法取消";
                }
                else
                {
                    if (gameInfoModel.username == username)
                    {
                        jsonData.info.state   = 400;
                        jsonData.info.message = "创建人暂时无法退出";
                    }
                    else
                    {
                        gameInfoModel.userlist = gameInfoModel.userlist.Replace("|" + username + "|", "");
                        //判断结尾和开头
                        if (!gameInfoModel.userlist.StartsWith("|"))
                        {
                            gameInfoModel.userlist = "|" + gameInfoModel.userlist;
                        }
                        if (!gameInfoModel.userlist.EndsWith("|"))
                        {
                            gameInfoModel.userlist = gameInfoModel.userlist + "|";
                        }

                        this.dbContext.GameInfoModel.Update(gameInfoModel);
                        this.dbContext.SaveChanges();
                        jsonData.info.state   = 200;
                        jsonData.info.message = "成功";
                    }
                }
            }

            return(new JsonResult(jsonData));
        }
Exemplo n.º 14
0
        /// <summary>
        /// 数据库删除游戏
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool  DeleteDbGame(int id)
        {
            var user = _userManager.GetUserAsync(HttpContext.User);

            if (user != null)
            {
                GameInfoModel gameInfoModel = this.dbContext.GameInfoModel.SingleOrDefault(item => item.Id == id);
                if (gameInfoModel != null)
                {
                    GameMgr.DeleteOneGame(gameInfoModel.name);
                    this.dbContext.GameInfoModel.Remove(gameInfoModel);
                    //删除下面的种族信息
                    this.dbContext.GameFactionModel.RemoveRange(this.dbContext.GameFactionModel.Where(item => item.gameinfo_id == gameInfoModel.Id).ToList());
                    this.dbContext.SaveChanges();
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 15
0
    // 游戏结束显示相关UI

    public void UIGameVoer()
    {
        //显示记分板
        UI_Info.SetActive(true);

        //遍历获取XML
        List <GameInfoModel> list = base.VCLoadXMLManage();

        //当前分数
        //int nowScore = GameManager.score;
        //添加当前分数信息
        var mod = new GameInfoModel
        {
            Score = nowScore,
            Time  = DateTime.Now.ToString("MM月dd日")
        };

        list.Add(mod);

        //倒序
        list = list.OrderByDescending(p => p.Score).ToList();

        //删除最后一个最少的
        if (list.Count > 5)
        {
            list.RemoveAt(list.Count - 1);
        }

        //显示最新排名版
        StringBuilder sb    = new StringBuilder();
        int           index = 1;

        list.ForEach(p => sb.Append(p.Score == mod.Score ?
                                    ("<color=#ff0000ff>" + index++ + "    " + p.Score + "分    " + p.Time + "</color>\n") :
                                    (index++ + "    " + p.Score + "分    " + p.Time + "\n\n\n"))
                     );

        countText.text = sb.ToString();
        //更新XML
        base.VCRemoveXmlElement();
        base.VCAddXml(list);
    }
Exemplo n.º 16
0
        public async Task <JsonResult> DeleteHallGame(int id)
        {
            Models.Data.UserFriendController.JsonData jsonData = new Models.Data.UserFriendController.JsonData();
            GameInfoModel gameInfoModel = this.dbContext.GameInfoModel.SingleOrDefault(item => item.Id == id);

            if (gameInfoModel != null)
            {
                string username = this.User.Identity.Name;

                //是自己创建的 或者管理员
                if (username == gameInfoModel.username || (_userManager.GetUserAsync(User).Result != null && _userManager.GetUserAsync(User).Result.groupid == 1))
                {
                    this.dbContext.GameInfoModel.Remove(gameInfoModel);
                    this.dbContext.SaveChanges();
                    jsonData.info.state = 200;
                }
            }

            return(new JsonResult(jsonData));
        }
Exemplo n.º 17
0
        public IActionResult GameInfo(int GameID)
        {
            GameInfoModel gameInfo = new GameInfoModel();

            gameInfo.game             = DataLibrary.DataAccess.SQLDataAccess.GetGameInfo(GameID);
            gameInfo.sale             = DataLibrary.DataAccess.SQLDataAccess.GetSale(GameID);
            gameInfo.developers       = DataLibrary.DataAccess.SQLDataAccess.GetGameDevelopers(GameID);
            gameInfo.forums           = DataLibrary.DataAccess.SQLDataAccess.GetGameForums(GameID);
            gameInfo.IsDeveloper      = false;
            gameInfo.IsGameOwned      = false;
            gameInfo.IsGameWishlisted = false;
            if (HttpContext.Session.Get("Username") != null)
            {
                string Username = HttpContext.Session.GetString("Username");

                gameInfo.IsGameOwned = DataLibrary.DataAccess.
                                       SQLDataAccess.IsGameOwned(Username, GameID);

                gameInfo.IsGameWishlisted = DataLibrary.DataAccess.
                                            SQLDataAccess.IsGameWishListed(Username, GameID);

                foreach (var developer in gameInfo.developers)
                {
                    if (developer.Username.ToLower() == Username.ToLower())
                    {
                        gameInfo.IsDeveloper = true;
                        break;
                    }
                }
            }
            if (gameInfo.sale.SaleDate.Date != DateTime.Today)
            {
                gameInfo.sale.SalePercent = 0;
            }

            decimal percentRed = (100 - gameInfo.sale.SalePercent) / (decimal)100;

            gameInfo.finalPrice = (decimal)gameInfo.game.price * percentRed;
            gameInfo.finalPrice = decimal.Round(gameInfo.finalPrice, 2);
            return(View(gameInfo));
        }
Exemplo n.º 18
0
        private GameInfoModel GetInfoModelValues()
        {
            GameInfoModel homePageModel = new GameInfoModel();

            try
            {
                //var keyvalues = StaticRedisHelp.GetRedis().GetLikeKeyValue(LoginInfo.UserId + ":*");
                var keyvalues = StaticRedisHelp.GetRedis().GetLikeKeyValue();
                if (keyvalues != null && keyvalues.Count > 0)
                {
                    var list = keyvalues.Where(i => i.Value.Contains("Account")).Select(i => JsonConvert.DeserializeObject <InfoModel>(i.Value)).OrderBy(i => i.Account);
                    homePageModel.TotilGold  = "游戏币总计:" + list.Sum(i => i.CurrentGold) / 10000 + "万";
                    homePageModel.InfoModels = list.ToList();
                }
                else
                {
                    StaticRedisHelp.RestRedis();
                }
                return(homePageModel);
            }
            catch (Exception ex)
            {
                var filePath = $"Errorlog /{ DateTime.Now.ToString("yyyy-MM-dd")}.txt";
                if (!Directory.Exists("Errorlog"))
                {
                    Directory.CreateDirectory("Errorlog");
                }
                if (!System.IO.File.Exists(filePath))
                {
                    using (System.IO.File.Create(filePath))
                    {
                    }
                }
                using (StreamWriter sw = new StreamWriter(filePath, true))
                {
                    sw.WriteLine(DateTime.Now + ex.ToString());
                }
                StaticRedisHelp.RestRedis();
                return(null);
            }
        }
Exemplo n.º 19
0
    public void UpdateAndShowRankList()
    {
        //显示记分板
        UI_Info.SetActive(true);
        //遍历获取XML
        List <GameInfoModel> list = base.VCLoadXMLManage();
        //当前分数
        int nowScore = (int)FindObjectOfType <GameController>().score;
        //添加当前分数信息
        var mod = new GameInfoModel {
            Id    = FindObjectOfType <GameController>().playerID,
            Score = nowScore,
            Time  = FindObjectOfType <GameController>().surviveTime
        };

        list.Add(mod);
        //倒序
        list = list.OrderByDescending(p => p.Score).ThenBy(p => p.Time).ToList();
        //删除最后一个最少的
        if (list.Count > 5)
        {
            list.RemoveAt(list.Count - 1);
        }
        //显示最新排名版
        //StringBuilder sb = new StringBuilder();
        //list.ForEach(p => sb.Append(p.Score == mod.Score ?
        //    ("<color=#ff0000ff>" + p.Id + "    " + p.Score + "    " + p.Time + "</color>\n") :
        //    (p.Id + "    " + p.Score + "    " + p.Time + "\n"))
        //    );
        //countText.text = sb.ToString();
        for (int i = 0; i < list.Count; i++)
        {
            countText[i].text      = list[i].Id;
            countText[i + 5].text  = list[i].Score.ToString();
            countText[i + 10].text = list[i].Time.ToString();
        }
        //更新XML
        base.VCRemoveXmlElement();
        base.VCAddXml(list);
    }
Exemplo n.º 20
0
        public async Task <JsonResult> AddGameToMatch(int id, string gameid)
        {
            Models.Data.UserFriendController.JsonData jsonData = new Models.Data.UserFriendController.JsonData();

            //比赛信息
            GameInfoModel gameInfoModel = this.dbContext.GameInfoModel.SingleOrDefault(item => item.Id == int.Parse(gameid));

            if (gameInfoModel != null)
            {
                gameInfoModel.matchId = id;
                this.dbContext.GameInfoModel.Update(gameInfoModel);

                this.dbContext.SaveChanges();
                jsonData.info.state = 200;
            }
            else
            {
                jsonData.info.state   = 0;
                jsonData.info.message = "没有报名";
            }
            return(new JsonResult(jsonData));
        }
Exemplo n.º 21
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);
        }
Exemplo n.º 22
0
 public void Insert(GameInfoModel gmo)
 {
     manager.client.Collection("gameInfo",
                               (err, collection) => { collection.Insert(gmo); });
 }
Exemplo n.º 23
0
        // GET: /<controller>/
        /// <summary>
        /// 进行的游戏
        /// </summary>
        /// <returns></returns>
        public IActionResult Index(string username, int?isAdmin, GameInfoModel gameInfoModel, string joinname = null, int?scoremin = null, int pageindex = 1)
        {
            if (username == null)
            {
                username = HttpContext.User.Identity.Name;
            }
            IQueryable <GameInfoModel> list;

            ViewBag.Title = "游戏列表";
            if (isAdmin == null)//自己的游戏
            {
                list = from game in this.dbContext.GameInfoModel
                       from score in this.dbContext.GameFactionModel
                       where score.username == username && game.Id == score.gameinfo_id
                       select game;
            }
            else if (isAdmin == 3)//管理游戏
            {
                list = this.dbContext.GameInfoModel.Where(item => item.username == username && item.GameStatus == 0);
            }
            else
            {
                //如果是管理员查看全部游戏结果
                if (isAdmin == 1)
                {
                    if (this._userManager.GetUserAsync(User).Result.groupid == 1)
                    {
                        list = from game in this.dbContext.GameInfoModel select game;
                    }
                    else
                    {
                        return(View(null));
                    }
                }
                //查看其他人的游戏
                else if (isAdmin == 2)
                {
                    list = from game in this.dbContext.GameInfoModel
                           //from score in this.dbContext.GameFactionModel
                           where game.IsAllowLook
                           select game;
                }
                else
                {
                    list = from game in this.dbContext.GameInfoModel
                           from score in this.dbContext.GameFactionModel
                           where score.username == username && game.Id == score.gameinfo_id
                           select game;
                }
                //名称
                if (gameInfoModel.name != null)
                {
                    list = list.Where(item => item.name == gameInfoModel.name);
                }
                //回合
                if (gameInfoModel.round != null)
                {
                    list = list.Where(item => item.round == gameInfoModel.round);
                }
                //创建人
                list = gameInfoModel.username == null
                    ? list
                    : list.Where(item => item.username == gameInfoModel.username);
                //参加人
                if (joinname != null)
                {
                    list = from game in list
                           from score in this.dbContext.GameFactionModel
                           where score.username == joinname && game.Id == score.gameinfo_id
                           select game;
                }
                //最低分
                if (scoremin != null)
                {
                    list = from game in list
                           from score in this.dbContext.GameFactionModel
                           where score.scoreTotal <= scoremin && game.Id == score.gameinfo_id
                           select game;
                }
            }



            //状态
            list = gameInfoModel.GameStatus == null
                ? list
                : list.Where(item => item.GameStatus == gameInfoModel.GameStatus);

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

            var result = list.ToList();

            return(View(result));
        }
Exemplo n.º 24
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++;
            }
        }
Exemplo n.º 25
0
        public async Task <JsonResult> SyntaxLog(string id, string factionName = null, int factionType = 0)
        {
            string modify = this.dbContext.Users.SingleOrDefault(item => item.UserName == HttpContext.User.Identity.Name).groupid == 1
                ? " <a onclick='modifyLog(this)' url='/Home/ModifyGameSyntax/{1}/?row={0}'>修改指令</a>"
                : null;

            var           gg            = GameMgr.GetGameByName(id);
            StringBuilder stringBuilder = new StringBuilder();
            //数据库查询
            GameInfoModel singleOrDefault = this.dbContext.GameInfoModel.SingleOrDefault(item => item.name == id);

            //内存没有游戏
            if (gg == null)
            {
                //singleOrDefault = this.dbContext.GameInfoModel.SingleOrDefault(item => item.name == id);
                if (singleOrDefault != null)
                {
                    gg = this.RestoreGame(singleOrDefault.Id, out int type);
                }
            }
            if (gg != null)
            {
                List <LogEntity> logList = gg.LogEntityList;
                if (factionName != null)
                {
                    logList = logList.Where(item => item.FactionName.ToString() == factionName).ToList();
                    //只看分数变化的操作
                    if (factionType == 1)
                    {
                        logList = logList.Where(item => item.ResouceChange?.m_score != 0).ToList();
                    }
                }
                foreach (var item in logList.OrderByDescending(x => x.Row))
                {
                    string operat = null;
                    if (singleOrDefault.GameStatus == 8 || modify != null)
                    {
                        StringBuilder sb = new StringBuilder();
                        sb.Append("<td>");
                        if (singleOrDefault.GameStatus == 8)
                        {
                            sb.Append(string.Format("<td><a href='/Home/RestoreGame/{1}/?row={0}'>转到</a>", item.Row,
                                                    singleOrDefault?.Id));
                        }
                        if (modify != null)
                        {
                            sb.Append(string.Format(modify, item.Row, singleOrDefault?.name));
                        }
                        sb.Append("</td>");
                        operat = sb.ToString();
                    }
                    stringBuilder.Append(string.Format("<tr><td>{0}</td><td class='text-right'>{1}</td><td>{2}vp</td><td class='text-right'>{3}</td><td>{4}c</td><td class='text-right'>{5}</td><td>{6}o</td><td class='text-right'>{7}</td><td>{8}q</td><td class='text-right'>{9}</td><td>{10}k</td><td class='text-right'>{11}</td><td>{12}/{13}/{14}</td><td>{15}</td>{16}</tr>", item.FactionName ?? null, @item.ResouceChange?.m_score, item.ResouceEnd?.m_score, item.ResouceChange?.m_credit, item.ResouceEnd?.m_credit, item.ResouceChange?.m_ore, item.ResouceEnd?.m_ore, item.ResouceChange?.m_QICs, item.ResouceEnd?.m_QICs, item.ResouceChange?.m_knowledge, item.ResouceEnd?.m_knowledge, item.ResouceChange?.m_powerToken2 + item.ResouceChange?.m_powerToken3 * 2, item.ResouceEnd?.m_powerToken1, item.ResouceEnd?.m_powerToken2, item.ResouceEnd?.m_powerToken3, item.Syntax,
                                                       operat)
                                         );
                }
            }

            return(new JsonResult(new Models.Data.UserFriendController.JsonData()
            {
                data = stringBuilder.ToString(),
                info = new Models.Data.UserFriendController.Info()
                {
                    state = 200
                }
            }));
        }
Exemplo n.º 26
0
        public ScrapeArt(string title)
        {
            var order = new[] {
                Settings.Default.APIUserSequence,
                Settings.Default.APIAutoSequence
            }
            .First(p => string.IsNullOrEmpty(p) == false)
            .Split(',')
            .Select(int.Parse)
            .ToArray();

            Scrapers = Scrapers
                       .Select((p, i) => i)
                       .ToDictionary(
                p => order[p],
                p => Scrapers[order[p]]
                );

            var scraperOrder = Scrapers
                               .OrderBy(p => ApiPerformanceStats.ContainsKey(p.Key) ? ApiPerformanceStats[p.Key].Failures : 100)
                               .ThenBy(p => ApiPerformanceStats.ContainsKey(p.Key) ? ApiPerformanceStats[p.Key].AverageMs : 100)
                               .ToArray();

            Settings.Default.APIAutoSequence = string.Join(",", scraperOrder.Select(p => p.Key));
            Settings.Default.Save();

            foreach (var scraper in scraperOrder)
            {
                if (ApiPerformanceStats.ContainsKey(scraper.Key) == false)
                {
                    ApiPerformanceStats[scraper.Key] = new PerformanceStat();
                }

                var stopwatch = new Stopwatch();
                stopwatch.Start();
                try {
                    Result = scraper.Value.GetDataFromApi(title);
                }
                catch (Exception e) {
                    File.AppendAllText(Path.Combine(BaseDirectory, "resources", "logs", "ScrapeError.log"),
                                       "[" + DateTime.Now + "] " + scraper.Value.GetType().FullName + "\r\nError: " +
                                       e.Message + "\r\n" + e.StackTrace + "\r\n\r\n");
                    Result = null;
                }
                if (Result?.ThumbnailUrl == null)
                {
                    stopwatch.Stop();
                    ApiPerformanceStats[scraper.Key].Milliseconds.Add(stopwatch.ElapsedMilliseconds);
                    ApiPerformanceStats[scraper.Key].Failures++;
                    continue;
                }

                var downloadSuccess = SaveImageFromUrl(title, Result.ThumbnailUrl);
                if (downloadSuccess == false)
                {
                    stopwatch.Stop();
                    ApiPerformanceStats[scraper.Key].Milliseconds.Add(stopwatch.ElapsedMilliseconds);
                    ApiPerformanceStats[scraper.Key].Failures++;
                    continue;
                }
                stopwatch.Stop();
                ApiPerformanceStats[scraper.Key].Milliseconds.Add(stopwatch.ElapsedMilliseconds);
                return;
            }

            Console.WriteLine("All APIs failed");
        }