Esempio n. 1
0
        public static async Task <int> RemoteAddPKRankItem(int serverId, TRankPKItem item)
        {
            if (RunServerId.Value < 0)
            {
                return(-1);
            }
            if (item == null)
            {
                return(-1);
            }
            if (item.UserId == 0)
            {
                return(-1);
            }

            return(await RpcProxy.RunAsync(typeof(RankCenterService), RunServerId.Value, RpcProxy.BuildArgs(serverId, item),
                                           () =>
            {
                if (PKRankPool == null)
                {
                    Logger.LogError("PKRankPool == null");
                    return -1;
                }
                //低于允许上榜的最低分
                if (item.Score < ConfigConstants.PK_RANKING_MIN)
                {
                    //从榜单池中移除
                    var rank = PKRankPool.Remove(item.UserId);
                    //删除数据
                    TRankPKItem.Cache.TryDelete(item.UserId.ToString());
                    Logger.LogDebug($"[Fail]ServerId[{serverId}] add PKRankItem UserId[{item.UserId}]Score[{item.Score}]Rank[{rank}] < PK_RANKING_MIN");
                }
                //允许上榜
                else
                {
                    //加入成功, 保存数据
                    var rank = PKRankPool.Add(item);
                    if (rank > 0)
                    {
                        TRankPKItem.Cache.AddOrUpdate(item);
                    }
                    Logger.LogDebug($"[Success]ServerId[{serverId}] add PKRankItem UserId[{item.UserId}]Score[{item.Score}]Rank[{rank}]");
                }
                return GetPKMinScore();
            }
                                           ));
        }
Esempio n. 2
0
        public static async Task <int> RemoteAddCOOPRankItem(int serverId, TRankCOOPItem item, int robotScore1, int robotScore2)
        {
            if (RunServerId.Value < 0)
            {
                return(-1);
            }
            if (item == null)
            {
                return(-1);
            }
            if ((item.UserId1) == 0 && (item.UserId2 == 0))
            {
                return(-1);
            }

            return(await RpcProxy.RunAsync(typeof(RankCenterService), RunServerId.Value, RpcProxy.BuildArgs(serverId, item, robotScore1, robotScore2),
                                           () =>
            {
                if (COOPRankPool == null)
                {
                    Logger.LogError("COOPRankPool == null");
                    return -1;
                }
                //低于允许上榜的最低回合数
                if (item.Round < ConfigConstants.COOP_RANKING_MIN)
                {
                    var key = item.PrimaryKey;
                    //从榜单池中移除
                    var rank = COOPRankPool.Remove(key);
                    //删除数据
                    TRankCOOPItem.Cache.TryDelete(key);
                    Logger.LogDebug($"[Fail]ServerId[{serverId}] add COOPRankItem Key[{key}]Round[{item.Round}]Rank[{rank}] < COOP_RANKING_MIN");
                }
                //允许上榜
                else
                {
                    var rank = COOPRankPool.Add(item);
                    //加入成功, 保存数据
                    if (rank > 0)
                    {
                        TRankCOOPItem.Cache.AddOrUpdate(item);
                    }
                    Logger.LogDebug($"[Success]ServerId[{serverId}] add COOPRankItem Key[{item.PrimaryKey}]Round[{item.Round}]Rank[{rank}]");
                    //机器人自动上榜PVP
                    if ((item.UserId1 < 0) && (robotScore1 >= ConfigConstants.PK_RANKING_MIN) && (!PKRankPool.ContainsKey(item.UserId1)))
                    {
                        var pkItem = new TRankPKItem(-1, item.UserId1, item.Name1, robotScore1, item.Team1.HeroBaseId, item.Team1.TowerPool, item.Team1.FieldId, DateTime.UtcNow.ToSecondsSinceEpoch());
                        PKRankPool.Add(pkItem);
                    }
                    if ((item.UserId2 < 0) && (robotScore2 >= ConfigConstants.PK_RANKING_MIN) && (!PKRankPool.ContainsKey(item.UserId2)))
                    {
                        var pkItem = new TRankPKItem(-1, item.UserId2, item.Name2, robotScore2, item.Team2.HeroBaseId, item.Team2.TowerPool, item.Team2.FieldId, DateTime.UtcNow.ToSecondsSinceEpoch());
                        PKRankPool.Add(pkItem);
                    }
                }
                return GetCOOPMinRound();
            }
                                           ));
        }