private static async void InitGameRankInfo()
        {
            DBProxyComponent proxyComponent = Game.Scene.GetComponent <DBProxyComponent>();
            List <Log_Rank>  logRankList    = new List <Log_Rank>();

            logRankList.Clear();
            List <GameRank> rankList = new List <GameRank>();

            logRankList.AddRange(await proxyComponent.QueryJsonRank(2));
            for (int i = 0; i < logRankList.Count; ++i)
            {
                List <PlayerBaseInfo> info = await proxyComponent.QueryJsonDB <PlayerBaseInfo>($"{{_id:{logRankList[i].UId}}}");

                GameRank rank = new GameRank();
                rank.PlayerName = info[0].Name;
                rank.WinCount   = logRankList[i].WinGameCount;
                rank.TotalCount = info[0].TotalGameCount;
                rank.Icon       = info[0].Icon;
                rank.UId        = info[0].Id;
                rankList.Add(rank);
            }
            Game.Scene.GetComponent <RankDataComponent>().SetGameRankData(rankList);
            logRankList = null;
            rankList    = null;
        }
        private async Task PublishGameRankAsync()
        {
            try
            {
                Console.WriteLine("\nCreate Game Rank Publication");

                Console.Write("\nEnter use id: ");
                var userId = Console.ReadLine() ?? string.Empty;

                Console.Write("Enter game name: ");
                var gameName = Console.ReadLine() ?? string.Empty;

                Console.Write("Enter game rating: ");
                var gameRating = double.Parse(Console.ReadLine() ?? string.Empty);

                var gameRank = new GameRank
                {
                    GameName = gameName,
                    GameRating = gameRating,
                    UserId = userId
                };

                var response = await _publishManager.PublishGameRankingAsync(gameRank);
                Console.WriteLine($"\nPublished game ranking successfully: {response.MessageId}");
            }
            catch (Exception e)
            {
                Console.ForegroundColor = ErrorForegroundColor;
                Console.WriteLine(e);
                Console.ForegroundColor = ForegroundColor;
            }
        }
Esempio n. 3
0
        public async Task <Unit> Handle(VoteGameCommand request, CancellationToken cancellationToken)
        {
            string currentProfileId = _userAccessor.GetCurrentProfileId();

            if (request.Vote <= 0 || request.Vote > 5)
            {
                throw new RestException(HttpStatusCode.Forbidden, new { message = "Rank must be between 1 and 5." });
            }

            if (currentProfileId == null)
            {
                throw new RestException(HttpStatusCode.Forbidden, new { message = "Not authorized." });
            }

            Domain.Entities.Game game = await _dbContext.Games.FirstOrDefaultAsync(x => x.IgdbId == request.Game.Id,
                                                                                   cancellationToken);

            if (game == null)
            {
                game = new Domain.Entities.Game
                {
                    Id          = Guid.NewGuid(), IgdbId = request.Game.Id, Title = request.Game.Name,
                    Description = request.Game.Summary, CoverPath = request.Game.Cover.Url
                };
                _dbContext.Games.Add(game);
            }

            GameRank gameRank = await _dbContext.Ranks.FirstOrDefaultAsync(x =>
                                                                           x.Game.IgdbId == game.IgdbId && x.ProfileId.ToString() == currentProfileId, cancellationToken);

            if (gameRank == null)
            {
                gameRank = new GameRank {
                    Game = game, ProfileId = new Guid(currentProfileId), Rank = request.Vote
                }
            }
            ;
            else if (gameRank.Rank == request.Vote)
            {
                gameRank.Rank = 0;
            }
            else
            {
                gameRank.Rank = request.Vote;
            }

            _dbContext.Ranks.Update(gameRank);

            bool success = await _dbContext.SaveChangesAsync(cancellationToken) > 0;

            if (success)
            {
                return(Unit.Value);
            }
            throw new RestException(HttpStatusCode.InternalServerError, new { message = "An error occurred." });
        }
Esempio n. 4
0
 protected void GetGameRank(G2C_Rank response, GameRank gameRank)
 {
     for (int i = 0; i < Game.Scene.GetComponent <RankDataComponent>().GetGameRankData().Count; ++i)
     {
         if (Game.Scene.GetComponent <RankDataComponent>().GetGameRankData()[i].WinCount > 0)
         {
             response.GameRankList.Add(Game.Scene.GetComponent <RankDataComponent>().GetGameRankData()[i]);
         }
     }
 }
Esempio n. 5
0
        public static async void RefreshGameRank()
        {
            DBProxyComponent proxyComponent = Game.Scene.GetComponent <DBProxyComponent>();

            gamePlayerList.Clear();
            gameRankList.Clear();
            gamePlayerList.AddRange(await proxyComponent.QueryJsonRank(2));
            for (int i = 0; i < gamePlayerList.Count; ++i)
            {
                List <PlayerBaseInfo> playerbaseinfos = await proxyComponent.QueryJsonDB <PlayerBaseInfo>($"{{_id:{gamePlayerList[i].UId}}}");

                GameRank rank = new GameRank();
                rank.PlayerName = playerbaseinfos[0].Name;
                rank.WinCount   = gamePlayerList[i].WinGameCount;
                rank.TotalCount = playerbaseinfos[0].TotalGameCount;
                rank.Icon       = playerbaseinfos[0].Icon;
                rank.UId        = playerbaseinfos[0].Id;
                gameRankList.Add(rank);
            }
            Game.Scene.GetComponent <RankDataComponent>().SetGameRankData(gameRankList);
        }
Esempio n. 6
0
        public void SetGameItem(GameRank gameRank, int index)
        {
            RankImg.gameObject.SetActive(index < 3);
            RankTxt.gameObject.SetActive(index >= 3);
            NameTxt.text = gameRank.PlayerName;
            Img.sprite   = CommonUtil.getSpriteByBundle("image_main", "win");
            GoldTxt.text = new StringBuilder().Append(gameRank.WinCount)
                           .ToString();
            if (RankTxt.gameObject.activeInHierarchy)
            {
                RankTxt.text = (index + 1).ToString();
            }
            HeadManager.setHeadSprite(Icon, gameRank.Icon);
            string rIcon = new StringBuilder().Append("Rank_")
                           .Append(index + 1)
                           .ToString();

            if (RankImg.gameObject.activeInHierarchy)
            {
                RankImg.sprite = CommonUtil.getSpriteByBundle("image_main", rIcon);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// 设置排行榜信息
        /// </summary>
        public async void GetRankInfo()
        {
            UINetLoadingComponent.showNetLoading();
            G2C_Rank g2cRank = (G2C_Rank)await Game.Scene.GetComponent <SessionComponent>()
                               .Session.Call(new C2G_Rank {
                Uid = PlayerInfoComponent.Instance.uid, RankType = 0
            });

            UINetLoadingComponent.closeNetLoading();

            //设置排行榜信息
            wealthRankList = g2cRank.RankList;
            gameRankList   = g2cRank.GameRankList;

            isOwnRank  = IsInRank(PlayerInfoComponent.Instance.uid);
            isGameRank = IsInGameRank(PlayerInfoComponent.Instance.uid);

            ownRank = GetWealthIndext(PlayerInfoComponent.Instance.uid);
            ownGame = GetGameIndext(PlayerInfoComponent.Instance.uid);
            ShowGameRank();
            ownWealthRank = g2cRank.OwnWealthRank;
            ownGameRank   = g2cRank.OwnGameRank;
            SetMyGameRank();
        }
        private async Task EnqueueGameRankAsync()
        {
            try
            {
                Console.WriteLine("\nEnqueue Game Rank");

                Console.Write("\nEnter queue name: ");
                var queueName = Console.ReadLine();

                Console.Write("\nEnter use id: ");
                var userId = Console.ReadLine();

                Console.Write("Enter game name: ");
                var gameName = Console.ReadLine();

                Console.Write("Enter game rating: ");
                var gameRating = double.Parse(Console.ReadLine());

                var gameRank = new GameRank
                {
                    GameName   = gameName,
                    GameRating = gameRating,
                    UserId     = userId
                };

                var messageId = await _gameRankQueueManager.EnqueueGameRankAsync(queueName, gameRank);

                Console.WriteLine($"\nPublished game ranking successfully: {messageId}");
            }
            catch (Exception e)
            {
                Console.ForegroundColor = ErrorForegroundColor;
                Console.WriteLine(e);
                Console.ForegroundColor = ForegroundColor;
            }
        }
Esempio n. 9
0
        protected override async void Run(Session session, C2G_Rank message, Action <G2C_Rank> reply)
        {
            G2C_Rank response = new G2C_Rank();

            try
            {
                DBProxyComponent      proxyComponent = Game.Scene.GetComponent <DBProxyComponent>();
                List <PlayerBaseInfo> mys            = await proxyComponent.QueryJson <PlayerBaseInfo>($"{{_id:{message.Uid}}}");

                if (mys.Count > 0)
                {
                    List <Log_Rank> ranks = await proxyComponent.QueryJson <Log_Rank>($"{{UId:{message.Uid}}}");

                    response.RankList     = new List <WealthRank>();
                    response.GameRankList = new List <GameRank>();
                    WealthRank wealthRank = new WealthRank();
                    GameRank   gameRank   = new GameRank();
                    wealthRank.Icon       = mys[0].Icon;
                    wealthRank.PlayerName = mys[0].Name;
                    if (ranks.Count > 0)
                    {
                        wealthRank.GoldNum = ranks[0].Wealth;
                        gameRank.WinCount  = ranks[0].WinGameCount;
                    }
                    else
                    {
                        wealthRank.GoldNum = 0;
                        gameRank.WinCount  = 0;
                    }
                    wealthRank.UId      = mys[0].Id;
                    gameRank.PlayerName = mys[0].Name;
                    gameRank.Icon       = mys[0].Icon;
                    gameRank.UId        = mys[0].Id;

                    if (message.RankType == 1)
                    {
                        GetWealthRank(response, wealthRank);
                        response.OwnWealthRank = wealthRank;
                    }
                    else if (message.RankType == 2)
                    {
                        GetGameRank(response, gameRank);
                        response.OwnGameRank = gameRank;
                    }
                    else
                    {
                        GetWealthRank(response, wealthRank);
                        GetGameRank(response, gameRank);
                        response.OwnGameRank   = gameRank;
                        response.OwnWealthRank = wealthRank;
                    }
                }
                else
                {
                    Log.Error($"玩家{message.Uid}playerbaseinfo为空");
                }

                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
Esempio n. 10
0
 public static void SetGameRank(GameRank Rank)
 {
     RankLevel = Rank;
 }