Exemplo n.º 1
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();
            }
                                           ));
        }
Exemplo n.º 2
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();
            }
                                           ));
        }
Exemplo n.º 3
0
        /// <summary>
        /// PK榜单结算
        /// </summary>
        private static async Task SettlePK(int userId)
        {
            //顺序敏感
            var profile = TUserProfile.Cache.FindKey(userId);

            if (profile == null)
            {
                Logger.LogError($"User[{userId}]: TUserProfile.Cache.FindKey({userId}) is null");
                return;
            }
            var curScore = profile.CurScore;

            //允许上榜
            if (curScore >= (ConfigConstants.PK_RANKING_MIN - 200))
            {
                //创建榜单条目
                var user = TUser.Cache.FindKey(userId);
                if (user == null)
                {
                    Logger.LogError($"User[{userId}]: TUser.Cache.FindKey({userId}) is null");
                    return;
                }
                var err = CardService.GetBattleTeamData(userId, (int)BattleType.PK,
                                                        out THero hero, out List <int> towerPool, out int _1, out int fieldId);
                if (err != ErrorCode.Success)
                {
                    return;
                }
                var nowTime = DateTime.UtcNow.ToSecondsSinceEpoch();
                var item    = new TRankPKItem(user.ServerId, userId, user.GetName(), curScore, hero.BattleHeroResId, towerPool, fieldId, nowTime);
                //发送榜单中心服, 请求上榜
                var rank = await RankCenterService.RemoteAddPKRankItem(Host.ServerId, item);

                Logger.LogDebug($"User[{userId}]: RemoteAddPKRankItem[{userId}]Score[{curScore}]Rank[{rank}]");
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// PK榜单条目是否有效
 /// </summary>
 private static bool CheckPKItemAvailable(TRankPKItem item) => item != null && item.Score >= ConfigConstants.PK_RANKING_MIN;