| | |
| | |
|
| | | import CommFunc
|
| | | import ShareDefine
|
| | | import IpyGameDataPY
|
| | | import CrossRealmMsg
|
| | | import PyGameDataStruct
|
| | | import ChPyNetSendPack
|
| | | import DataRecordPack
|
| | | import NetPackCommon
|
| | | import PyDataManager
|
| | | import CrossRealmPK
|
| | | import GameWorld
|
| | |
|
| | | import operator
|
| | |
| | | self.__billboardType = billboardType
|
| | | self.__groupValue1 = groupValue1
|
| | | self.__groupValue2 = groupValue2
|
| | | self.__maxCount = ShareDefine.CrossBillboard_MaxDataCount.get(billboardType, 100)
|
| | | self.__crossServerDataVer = 0 # 主服榜单数据版本
|
| | | self.__clientServerDataVer = 0 # 子服榜单数据版本
|
| | | self.__billboardList = [] # [tagDBCrossBillboard, ...]
|
| | | self.__idIndexDict = {} # {id:index, ...}
|
| | | self.__idOrderDict = {} # {id:名次, ...}
|
| | | self.__orderRuleList = None
|
| | | self.__sortDelay = False # 是否需要延迟排序
|
| | |
| | | self.SaveDRData("Clear")
|
| | | self.__billboardList = [] # [tagDBCrossBillboard, ...]
|
| | | self.__idOrderDict = {} # {id:名次, ...}
|
| | | self.__idIndexDict = {}
|
| | |
|
| | | self.UpdCrossServerDataVer(0)
|
| | | return
|
| | |
| | | % (self.__billboardType, self.__groupValue1, self.__groupValue2, len(self.__billboardList)))
|
| | | self.__billboardList.sort(key=operator.attrgetter("CmpValue", "CmpValue2", "CmpValue3"), reverse=True)
|
| | | self.__idOrderDict = {} # 排序后重置,下次查询时更新并缓存
|
| | | self.__idIndexDict = {}
|
| | | self.__sortDelay = False
|
| | | self.UpdCrossServerDataVer()
|
| | | return
|
| | |
| | | @param findID: 查找的ID
|
| | | @return: None or PyGameDataStruct.tagDBCrossBillboard()
|
| | | '''
|
| | | idOrderDict = self.GetIDOrderDict()
|
| | | if findID not in idOrderDict:
|
| | | self.GetIDOrderDict()
|
| | | if findID not in self.__idIndexDict:
|
| | | return None
|
| | | order = idOrderDict[findID]
|
| | | return self.__billboardList[order - 1]
|
| | | idIndex = self.__idIndexDict[findID]
|
| | | if idIndex >= len(self.__billboardList):
|
| | | return None
|
| | | return self.__billboardList[idIndex]
|
| | |
|
| | | def IndexOfByID(self, findID):
|
| | | ''' 根据ID查询所在榜单索引
|
| | | @param findID: 查找的ID
|
| | | @return: -1 or >=0
|
| | | '''
|
| | | idOrderDict = self.GetIDOrderDict()
|
| | | if findID not in idOrderDict:
|
| | | self.GetIDOrderDict()
|
| | | if findID not in self.__idIndexDict:
|
| | | return -1
|
| | | order = idOrderDict[findID]
|
| | | return order - 1
|
| | | idIndex = self.__idIndexDict[findID]
|
| | | return idIndex
|
| | |
|
| | | def SaveDRData(self, eventName="", addDataDict={}):
|
| | | ## 记录流向数据
|
| | |
| | | def GetIDOrderDict(self):
|
| | | ## 获取ID对应名次字典
|
| | | # @return: {ID:名次, ...} 名次从1开始
|
| | | if not self.__idOrderDict:
|
| | | if not self.__idOrderDict or not self.__idIndexDict:
|
| | | self.__idOrderDict = {}
|
| | | self.__idIndexDict = {}
|
| | | if self.__orderRuleList:
|
| | | billboardDataCount = self.GetCount()
|
| | | rankPre = 0
|
| | |
| | | self.__idOrderDict[billboardData.ID] = orderReal
|
| | | orderCountTotal -= 1
|
| | | billboardIndex += 1
|
| | | for order, billboardData in enumerate(self.__billboardList, 1):
|
| | | self.__idIndexDict[billboardData.ID] = order - 1
|
| | | else:
|
| | | for order, billboardData in enumerate(self.__billboardList, 1):
|
| | | self.__idOrderDict[billboardData.ID] = order
|
| | | self.__idIndexDict[billboardData.ID] = order - 1
|
| | | return self.__idOrderDict
|
| | |
|
| | | def SetOrderRuleList(self, orderRuleList):
|
| | |
| | | # @param orderRuleList: 排名所需值规则列表 [[order, needCmpValue], ...]
|
| | | self.__orderRuleList = orderRuleList
|
| | | self.__idOrderDict = {} # 设置后需重置,可能配置规则变化了导致实际排名可能变化
|
| | | self.__idIndexDict = {}
|
| | | GameWorld.Log("设置排名所需值规则列表: billboardType=%s,groupValue1=%s,groupValue2=%s, %s"
|
| | | % (self.__billboardType, self.__groupValue1, self.__groupValue2, orderRuleList))
|
| | | return
|
| | |
|
| | | def GetCount(self): return len(self.__billboardList)
|
| | | def GetMaxCount(self): return self.__maxCount
|
| | | def GetMaxCount(self):
|
| | | maxCountDict = IpyGameDataPY.GetFuncEvalCfg("CrossBillboardSet", 1, {})
|
| | | return maxCountDict.get(self.__billboardType, 100)
|
| | |
|
| | | def At(self, i): return self.__billboardList[i]
|
| | | def IsFull(self): return len(self.__billboardList) >= self.__maxCount
|
| | | def At(self, i):
|
| | | billData = self.__billboardList[i]
|
| | | if not billData and False:
|
| | | billData = PyGameDataStruct.tagDBCrossBillboard() # 不会执行到,只为了.出代码提示
|
| | | return billData
|
| | | |
| | | def IsFull(self): return len(self.__billboardList) >= self.GetMaxCount()
|
| | |
|
| | | def UpdCrossServerDataVer(self, version=None):
|
| | | ## 更新跨服榜单数据版本号,用于跨服主服、子服验证数据版本,同步榜单数据用
|
| | |
| | | if syncBillboardList != None:
|
| | | self.__billboardList = self.__billboardList[:len(syncBillboardList)] # 直接用本服以后的排行数据实例clear后覆盖更新,不足的创建新实例
|
| | | self.__idOrderDict = {}
|
| | | self.__idIndexDict = {}
|
| | | for i, syncData in enumerate(syncBillboardList):
|
| | | ID, ID2, Name1, Name2, Type2, Value1, Value2, CmpValue, CmpValue2, CmpValue3, Value3, Value4, Value5, Value6, Value7, Value8, UserData = syncData
|
| | | if i < len(self.__billboardList):
|
| | |
| | | billboardData.CmpValue3 = CmpValue3
|
| | |
|
| | | self.__idOrderDict[ID] = i + 1
|
| | | self.__idIndexDict[ID] = i
|
| | |
|
| | | self.__clientServerDataVer = crossServerDataVer
|
| | |
|
| | |
| | | def CopyBillboardOnDay():
|
| | | billboardMgr = PyDataManager.GetCrossBillboardManager()
|
| | | for billboardType in ShareDefine.CrossBillboardTypeList:
|
| | | if billboardType in [ShareDefine.Def_CBT_BossTrialSubmitBak, ShareDefine.Def_CBT_BossTrialSubmitFamilyBak]:
|
| | | if billboardType in [ShareDefine.Def_CBT_BossTrialSubmitBak, ShareDefine.Def_CBT_BossTrialSubmitFamilyBak, ShareDefine.Def_CBT_CrossRealmPK]:
|
| | | continue
|
| | | groupList = billboardMgr.GetBillboardGroupList(billboardType)
|
| | | for billboardType, groupValue1, groupValue2 in groupList:
|
| | |
| | | GameWorld.DebugLog("玩家请求查看跨服排行榜: billboardType=%s,groupValue1=%s,groupValue2=%s" % (billboardType, groupValue1, groupValue2))
|
| | |
|
| | | # 请求查询跨服服务器
|
| | | dataMsg = {"BillboardType":billboardType, "GroupValue1":groupValue1, "GroupValue2":groupValue2,
|
| | | "QueryData":{"EventName":"View", "PlayerID":playerID, "StartIndex":startIndex, "WatchCnt":watchCnt, "WatchID":watchID}}
|
| | | dataMsg = {"BillboardType":billboardType, "GroupValue1":groupValue1, "GroupValue2":groupValue2, "PlayerID":playerID, |
| | | "QueryType":"View", "QueryData":{"StartIndex":startIndex, "WatchCnt":watchCnt, "WatchID":watchID}}
|
| | | CrossRealmMsg.SendMsgToCrossServer(ShareDefine.ClientServerMsg_QueryBillboard, dataMsg)
|
| | | return
|
| | |
|
| | | def OnQueryPlayerBillboardRank(playerID, funcName, funcData, billboardType, groupValue1, groupValue2=0, tagPlayerID=0):
|
| | | ## 查询玩家ID排名
|
| | | if GameWorld.IsCrossServer():
|
| | | return
|
| | | if billboardType not in ShareDefine.CrossBillboardTypeList:
|
| | | return
|
| | | if not tagPlayerID:
|
| | | tagPlayerID = playerID # 默认查自己
|
| | | dataMsg = {"BillboardType":billboardType, "GroupValue1":groupValue1, "GroupValue2":groupValue2, "PlayerID":playerID,
|
| | | "QueryType":"Ranking", "QueryData":{"PlayerID":tagPlayerID, "funcName":funcName, "funcData":funcData}}
|
| | | CrossRealmMsg.SendMsgToCrossServer(ShareDefine.ClientServerMsg_QueryBillboard, dataMsg)
|
| | | return
|
| | |
|
| | |
| | | billboardType = msgData["BillboardType"]
|
| | | groupValue1 = msgData["GroupValue1"]
|
| | | groupValue2 = msgData["GroupValue2"]
|
| | | playerID = msgData.get("PlayerID", 0) # 发起的玩家ID
|
| | | queryType = msgData.get("QueryType", "") # 原数据返回子服
|
| | | queryData = msgData.get("QueryData", {}) # 原数据返回子服
|
| | | SyncCrossBillboardToClientServer(billboardType, groupValue1, groupValue2, [serverGroupID], queryData)
|
| | | SyncCrossBillboardToClientServer(billboardType, groupValue1, groupValue2, [serverGroupID], playerID, queryType, queryData)
|
| | | return
|
| | |
|
| | | def SyncCrossBillboardToClientServer(billboardType, groupValue1, groupValue2, serverGroupIDList=None, queryData=None):
|
| | | def SyncCrossBillboardToClientServer(billboardType, groupValue1, groupValue2, serverGroupIDList=None, playerID=0, queryType="", queryData=None):
|
| | | ## 同步跨服榜单到子服
|
| | | if not GameWorld.IsCrossServer():
|
| | | return
|
| | |
| | | billboardObj = billboardMgr.GetCrossBillboard(billboardType, groupValue1, groupValue2)
|
| | | billboardObj.DoDelaySort()
|
| | | idOrderDict = billboardObj.GetIDOrderDict()
|
| | | crossServerDataVer = billboardObj.GetCrossServerDataVer()
|
| | | msgData = {"BillboardType":billboardType, "GroupValue1":groupValue1, "GroupValue2":groupValue2,
|
| | | "QueryData":queryData, "CrossServerDataVer":crossServerDataVer}
|
| | | msgData = {"BillboardType":billboardType, "GroupValue1":groupValue1, "GroupValue2":groupValue2, "PlayerID":playerID,
|
| | | "QueryType":queryType, "QueryData":queryData}
|
| | | |
| | | # 查询名次
|
| | | if queryType == "Ranking":
|
| | | tagPlayerID = queryData.get("PlayerID", 0)
|
| | | if not tagPlayerID:
|
| | | return
|
| | | queryData["OrderIndex"] = idOrderDict.get(tagPlayerID, 0) - 1 # -1-未上榜,0-第一名
|
| | | CrossRealmMsg.SendMsgToClientServer(ShareDefine.CrossServerMsg_SyncBillboard, msgData, serverGroupIDList)
|
| | | return
|
| | |
|
| | | # 有查询数据时才同步榜单数据列表,否则只同步数据版本号
|
| | | if queryData:
|
| | |
| | | billboardType = msgData["BillboardType"]
|
| | | groupValue1 = msgData["GroupValue1"]
|
| | | groupValue2 = msgData["GroupValue2"]
|
| | | crossServerDataVer = msgData["CrossServerDataVer"]
|
| | | syncBillboardList = msgData.get("BillboardDataList")
|
| | | GameWorld.DebugLog("收到跨服服务器同步的排行榜信息: billboardType=%s,groupValue1=%s,groupValue2=%s,crossServerDataVer=%s" |
| | | % (billboardType, groupValue1, groupValue2, crossServerDataVer))
|
| | | |
| | | #billboardMgr = PyDataManager.GetCrossBillboardManager()
|
| | | #billboardObj = billboardMgr.GetCrossBillboard(billboardType, groupValue1, groupValue2)
|
| | | #billboardObj.UpdClientServerBillboard(crossServerDataVer, syncBillboardList)
|
| | | |
| | | queryData = msgData.get("QueryData")
|
| | | if not queryData:
|
| | | playerID = msgData.get("PlayerID", 0) # 发起的玩家ID
|
| | | queryType = msgData.get("QueryType", "")
|
| | | queryData = msgData.get("QueryData", {})
|
| | | GameWorld.DebugLog("收到跨服服务器同步的排行榜信息: billboardType=%s,groupValue1=%s,groupValue2=%s,queryType=%s" |
| | | % (billboardType, groupValue1, groupValue2, queryType), playerID)
|
| | | if not queryType or not queryData:
|
| | | return
|
| | |
|
| | | eventName = queryData.get("EventName")
|
| | | #eventData = queryData.get("EventData")
|
| | | queryPlayerID = queryData.get("PlayerID", 0)
|
| | | if not eventName or not queryPlayerID:
|
| | | return
|
| | | |
| | | queryPlayer = GameWorld.GetPlayerManager().FindPlayerByID(queryPlayerID)
|
| | | if not queryPlayer:
|
| | | return
|
| | | |
| | | if eventName == "View": |
| | | if queryType == "View":
|
| | | queryPlayer = GameWorld.GetPlayerManager().FindPlayerByID(playerID)
|
| | | if not queryPlayer:
|
| | | return
|
| | | watchID = queryData.get("WatchID", 0)
|
| | | syncBillboardList = msgData.get("BillboardDataList")
|
| | | SyncCrossBillboardToPlayer(queryPlayer, billboardType, groupValue1, groupValue2, syncBillboardList, watchID)
|
| | | #else:
|
| | | # idOrderDict = billboardObj.GetIDOrderDict()
|
| | | # order = idOrderDict.get(queryPlayerID, 0)
|
| | | # sysMsg = str([billboardType, groupValue1, groupValue2, eventName, eventData, order])
|
| | | # queryPlayer.MapServer_QueryPlayerResult(0, 0, "CrossBillboardOrder", sysMsg, len(sysMsg))
|
| | |
|
| | | elif queryType == "Ranking":
|
| | | funcName = queryData.get("funcName", "")
|
| | | funcData = queryData.get("funcData", {})
|
| | | #tagPlayerID = queryData.get("PlayerID", 0)
|
| | | orderIndex = queryData.get("OrderIndex", 0)
|
| | | if funcName == "QueryCrossPKSeasonOrder":
|
| | | CrossRealmPK.OnQueryCrossPKSeasonOrderRet(playerID, funcData, orderIndex)
|
| | | |
| | | return
|
| | |
|
| | | def SyncCrossBillboardToPlayer(curPlayer, billboardType, groupValue1, groupValue2, billboardList, watchID):
|
| | |
| | | billboardData.BillboardType = billboardType
|
| | | billboardData.ID = dataID
|
| | | billboardData.ID2 = id2
|
| | | billboardData.Name1 = "" if len(name1) > 33 else name1
|
| | | billboardData.Name2 = "" if len(name2) > 33 else name2
|
| | | billboardData.SetName1(name1)
|
| | | billboardData.SetName2(name2)
|
| | | billboardData.Type2 = type2
|
| | | billboardData.Value1 = value1
|
| | | billboardData.Value2 = value2
|