| | |
| | | using System;
|
| | | using System.Collections;
|
| | | using System.Collections.Generic;
|
| | | using UnityEngine;
|
| | |
|
| | |
| | | public class RankModel : GameSystemManager<RankModel>
|
| | | {
|
| | | public event Action<int> onRankRefresh;
|
| | | public event Action<int> onMyRankRefresh;
|
| | | //public event Action<int> onMyRankRefresh;
|
| | | |
| | | //排行榜滚动显示的最大数量 类型
|
| | | Dictionary<int, int> ranksShowMaxCnt = new Dictionary<int, int>();
|
| | |
|
| | | //分页查询
|
| | | Dictionary<int, int> queryRankCD = new Dictionary<int, int>(); //首次查询CD,不影响后续的分页查询
|
| | | //分页查询 排名索引按字段存储 1代表第一名
|
| | | Dictionary<int, Dictionary<int, RankData>> m_RankPageDatas = new Dictionary<int, Dictionary<int, RankData>>(); |
| | | //类型:ID -排名索引,通过ID进行排重删除 不同名次 同ID的数据
|
| | | Dictionary<int, Dictionary<int, int>> m_RankIDToIndex = new Dictionary<int, Dictionary<int, int>>();
|
| | |
|
| | | //监听排行榜显示名次,用于分页查询,第一页查询由外部触发
|
| | | //使用场景 如界面排行榜滚动的时候每次查询30个排名名额,在显示大于m*30 +20名时,监听下一页,查询m+1页
|
| | | int pageCnt = 20; //每页查询条数
|
| | | int queryPointNum = 12; //查询点
|
| | | int queryPageCD = 60; //内部查询点CD 避免不断上下滑动的时候过于频繁查询,外部使用重新打开的时候可以重置CD
|
| | | Dictionary<int, float> queryPageTimes = new Dictionary<int, float>(); //查询页CD
|
| | | Dictionary<int, int> ranksServerMaxCnt = new Dictionary<int, int>(); //服务器排行榜当前总数量(动态变化),分页查询的时候过滤用
|
| | |
|
| | |
|
| | |
|
| | | public override void Init()
|
| | | {
|
| | | DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent += OnBeforePlayerDataInitialize;
|
| | | ParseConfig();
|
| | | }
|
| | |
|
| | | public void OnBeforePlayerDataInitialize()
|
| | |
| | | m_RankPageDatas.Clear();
|
| | | m_RankIDToIndex.Clear();
|
| | | queryRankCD.Clear();
|
| | | }
|
| | |
|
| | | void ParseConfig()
|
| | | {
|
| | | var config = FuncConfigConfig.Get("BillboardSet");
|
| | | ranksShowMaxCnt = ConfigParse.ParseIntDict(config.Numerical3);
|
| | | }
|
| | |
|
| | | public int GetRankShowMaxCnt(int type)
|
| | | {
|
| | | if (ranksShowMaxCnt.ContainsKey(type))
|
| | | {
|
| | | return ranksShowMaxCnt[type];
|
| | | }
|
| | | return 100;
|
| | | }
|
| | |
|
| | | public override void Release()
|
| | |
| | |
|
| | |
|
| | | #region 分页查询
|
| | | Dictionary<int, int> queryRankCD = new Dictionary<int, int>(); //首次查询CD,不影响后续的分页查询
|
| | | //分页查询 排名索引按字段存储 1代表第一名
|
| | | Dictionary<int, Dictionary<int, RankData>> m_RankPageDatas = new Dictionary<int, Dictionary<int, RankData>>(); |
| | | //类型:ID -排名索引,通过ID进行排重删除 不同名次 同ID的数据
|
| | | Dictionary<int, Dictionary<int, int>> m_RankIDToIndex = new Dictionary<int, Dictionary<int, int>>();
|
| | |
|
| | |
|
| | | //!!!本服分页查询使用说明
|
| | |
| | | queryRankCD[type] = (int)Time.time;
|
| | | }
|
| | |
|
| | | //监听排行榜显示名次,用于分页查询,第一页查询由外部触发
|
| | | //使用场景 如界面排行榜滚动的时候每次查询30个排名名额,在显示大于m*30 +20名时,监听下一页,查询m+1页
|
| | | int pageCnt = 20; //每页查询条数
|
| | | int queryPointNum = 12; //查询点
|
| | | int queryPageCD = 60; //内部查询点CD 避免不断上下滑动的时候过于频繁查询,外部使用重新打开的时候可以重置CD
|
| | | Dictionary<int, float> queryPageTimes = new Dictionary<int, float>(); //查询页CD
|
| | |
|
| | | public void ListenRankPage(int type, int index, int groupValue1 = 0, int groupValue2 = 0)
|
| | | {
|
| | | int page = index / pageCnt;
|
| | |
| | | {
|
| | | if (queryPageTimes.ContainsKey(page) && Time.realtimeSinceStartup - queryPageTimes[page] < queryPageCD)
|
| | | return;
|
| | | if (ranksServerMaxCnt.ContainsKey(type))
|
| | | { |
| | | if(index >= ranksServerMaxCnt[type])
|
| | | {
|
| | | //超过服务器已上榜的总数量,比如总榜单是100名,当前只有8名玩家上榜,往下滚动就不再查询
|
| | | return;
|
| | | }
|
| | | }
|
| | | Debug.LogFormat("分页查询:{0} - {1}", index, page);
|
| | | QueryRankByPage(type, pageCnt * (page + 1), pageCnt, 0, true, groupValue1, groupValue2);
|
| | | queryPageTimes[page] = Time.realtimeSinceStartup;
|
| | |
| | | m_RankIDToIndex.Add(rankType, new Dictionary<int, int>());
|
| | | }
|
| | |
|
| | | if (!ranksServerMaxCnt.ContainsKey(rankType))
|
| | | { |
| | | ranksServerMaxCnt.Add(rankType, package.DataTotal);
|
| | | }
|
| | | ranksServerMaxCnt[rankType] = package.DataTotal;
|
| | |
|
| | | for (int i = 0; i < package.PageDataCnt; i++)
|
| | | {
|
| | | int id = (int)package.PageDataList[i].ID;
|
| | |
| | | }
|
| | | ReSetRankData(m_RankPageDatas[rankType][orderIndex], package.ViewIDDataList[i], package.Type);
|
| | | }
|
| | | onMyRankRefresh?.Invoke(package.Type);
|
| | | //onMyRankRefresh?.Invoke(package.Type); 同时查询没有单独返回数据,暂时不要这个事件
|
| | | }
|
| | | else
|
| | | {
|
| | | onRankRefresh?.Invoke(package.Type);
|
| | | }
|
| | |
|
| | | onRankRefresh?.Invoke(package.Type);
|
| | |
|
| | |
|
| | | }
|
| | |
|
| | | //排名从0 开始
|
| | | //排名从1 开始
|
| | | //如果是跨服排行榜 类型可能因跨服功能不同 由分组分赛季等情况组合
|
| | | public Dictionary<int, RankData> GetRankPageDatas(int type)
|
| | | {
|
| | |
| | | return datas;
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | | //查询指定目标排名的数据
|
| | | public RankData GetRankDataByRank(int type, int rank)
|
| | | {
|
| | | Dictionary<int, RankData> rankDatas = null;
|
| | | RankData rankData = null;
|
| | | if (m_RankPageDatas.TryGetValue(type, out rankDatas))
|
| | | {
|
| | | rankDatas.TryGetValue(rank, out rankData);
|
| | | }
|
| | | return rankData;
|
| | | }
|
| | |
|
| | |
|
| | |
| | | return null;
|
| | | }
|
| | |
|
| | | public RankData GetMyRankByID(int type, int queryID)
|
| | | public RankData GetRankByID(int type, int queryID)
|
| | | {
|
| | | Dictionary<int, RankData> rankDatas = null;
|
| | | if (m_RankPageDatas.TryGetValue(type, out rankDatas))
|
| | |
| | | #endregion
|
| | | }
|
| | |
|
| | | // 默认情况,各个榜可能有所变化
|
| | | // 玩家个人榜
|
| | | // ID - 玩家ID
|
| | | // Name1 - 玩家名
|
| | | // Name2 - 游戏账号
|
| | | // Type2 - 职业
|
| | | // Value1 - 官职
|
| | | // Value2 - 称号ID
|
| | | // Value3 - 头像
|
| | | // Value4 - 头像框
|
| | | // Value5 - 主角形象
|
| | | // cmpValue 比较值亿
|
| | | // cmpValue2 比较值小于亿
|
| | | // cmpValue3 时间戳
|
| | | // ---------------------------------------
|
| | | // 仙盟榜
|
| | | // ID - 仙盟ID
|
| | | // ID2 - 盟主ID
|
| | | // Name1 - 仙盟名
|
| | | // Name2 - 盟主名
|
| | | // Value1 - 总战力,整除亿部分
|
| | | // Value2 - 总战力,求余亿部分
|
| | | // Value3 - 徽章
|
| | | // Value4 - 仙盟等级
|
| | | // Value5 - 仙盟ServerID
|
| | |
|
| | |
|
| | | public class RankData
|
| | | {
|
| | | public int type; //排行榜类型
|