Exemplo n.º 1
0
        /// <summary>
        /// 尝试重新加载所有榜单
        /// </summary>
        public static async Task TryReloadAllRank(object state)
        {
            if (PKRankPool == null)
            {
                Logger.LogError("PKRankPool== null");
                return;
            }
            if (COOPRankPool == null)
            {
                Logger.LogError("COOPRankPool == null");
                return;
            }
            lock (RankLoadLock)
            {
                //未到加载时间
                if (DateTime.UtcNow < RankNextLoadDateTime)
                {
                    return;
                }
                //更新下次加载时间
                //内网 1分钟 | 外网 10分钟
                var addMinutes = ConfigService.DevelopmentEnv.Value ? 1 : 10;
                RankNextLoadDateTime = DateTime.UtcNow.AddMinutes(addMinutes);
                RankNextLoadTime     = RankNextLoadDateTime.ToSecondsSinceEpoch();
                Logger.LogDebug($"RankNextLoadTime[{RankNextLoadDateTime}]");
            }
            var pack = await RankCenterService.RemoteLoadPack(Host.ServerId);

            if (pack == null)
            {
                Logger.LogError("Fail to load rank pack from rank center server");
                return;
            }
            PKRankPool.ClearAndAdd(pack.PKList, CheckPKItemAvailable);
            COOPRankPool.ClearAndAdd(pack.COOPList, CheckCOOPItemAvailable);
            Logger.LogDebug($"Load PKRankPool Count[{PKRankPool.Count}]");
            Logger.LogDebug($"Load COOPRankPool Count[{COOPRankPool.Count}]");
        }
Exemplo n.º 2
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}]");
            }
        }