| | |
| | | self.__crossServerDataVer = 0 # 主服榜单数据版本
|
| | | self.__clientServerDataVer = 0 # 子服榜单数据版本
|
| | | self.__billboardList = [] # [tagDBCrossBillboard, ...]
|
| | | self.__idIndexDict = {} # {id:index, ...}
|
| | | self.__idOrderDict = {} # {id:名次, ...}
|
| | | self.__orderRuleList = None
|
| | | self.__sortDelay = False # 是否需要延迟排序
|
| | | return
|
| | |
|
| | | def GetBillboardType(self): return self.__billboardType
|
| | |
| | | def GetGroupValue2(self): return self.__groupValue2
|
| | |
|
| | | def ClearData(self):
|
| | | GameWorld.Log("CrossBillboard ClearData billboardType=%s,groupValue1=%s,groupValue2=%s" |
| | | % (self.__billboardType, self.__groupValue1, self.__groupValue2))
|
| | | GameWorld.Log("CrossBillboard ClearData billboardType=%s,groupValue1=%s,groupValue2=%s,dataCount=%s" |
| | | % (self.__billboardType, self.__groupValue1, self.__groupValue2, len(self.__billboardList)))
|
| | | if GameWorld.IsCrossServer():
|
| | | self.SaveDRData()
|
| | | self.SaveDRData("Clear")
|
| | | self.__billboardList = [] # [tagDBCrossBillboard, ...]
|
| | | self.__idOrderDict = {} # {id:名次, ...}
|
| | | self.__idIndexDict = {}
|
| | |
|
| | | self.UpdCrossServerDataVer(0)
|
| | | return
|
| | |
|
| | | def SortData(self):
|
| | | GameWorld.DebugLog("跨服榜单排序: billboardType=%s,groupValue1=%s,groupValue2=%s,dataCount=%s" |
| | | % (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
|
| | | |
| | | def SetDelaySort(self):
|
| | | ## 设置延迟排序
|
| | | GameWorld.DebugLog("跨服榜单设置延迟排序: billboardType=%s,groupValue1=%s,groupValue2=%s,dataCount=%s" |
| | | % (self.__billboardType, self.__groupValue1, self.__groupValue2, len(self.__billboardList)))
|
| | | self.__sortDelay = True
|
| | | self.UpdCrossServerDataVer()
|
| | | return
|
| | | |
| | | def DoDelaySort(self):
|
| | | ## 延迟排序
|
| | | if not self.__sortDelay:
|
| | | return
|
| | | self.SortData()
|
| | | return
|
| | |
|
| | | def AddBillboardData(self, billboardData):
|
| | |
| | | @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):
|
| | | def SaveDRData(self, eventName="", addDataDict={}):
|
| | | ## 记录流向数据
|
| | | eventTypeName = "CrossBillboard_%s" % (self.__billboardType)
|
| | | drDict = {"BillboardType":self.__billboardType, "GroupValue1":self.__groupValue1, "GroupValue2":self.__groupValue2, |
| | | "DataCount":len(self.__billboardList)}
|
| | | DataRecordPack.SendEventPack(eventTypeName, drDict)
|
| | | |
| | | self.DoDelaySort()
|
| | | dataCount = len(self.__billboardList)
|
| | | if not dataCount:
|
| | | return
|
| | | |
| | | idOrderDict = self.GetIDOrderDict()
|
| | | serverTime = GameWorld.GetServerTime()
|
| | | timeStr = "%02d%02d%02d%s" % (serverTime.hour, serverTime.minute, serverTime.second, str(serverTime.microsecond)[:3])
|
| | | eventTypeStr = "Billboard_%s_%s_%s_%s_%s" % (self.__billboardType, self.__groupValue1, self.__groupValue2, eventName, timeStr)
|
| | | |
| | | dataDict = {"BillboardType":self.__billboardType, "DataCount":dataCount, "addDataDict":addDataDict,
|
| | | "GroupValue1":self.__groupValue1, "GroupValue2":self.__groupValue2}
|
| | | DataRecordPack.SendEventPack(eventTypeStr, dataDict)
|
| | | |
| | | for index, billboardData in enumerate(self.__billboardList):
|
| | | dataDict = {"BillboardType":billboardData.BillboardType, "GroupValue1":billboardData.GroupValue1, |
| | | "GroupValue2":billboardData.GroupValue2, "Type2":billboardData.Type2,
|
| | | "ID":billboardData.ID, "ID2":billboardData.ID2, "Place":index, |
| | | rank = idOrderDict.get(billboardData.ID, index + 1)
|
| | | dataDict = {"Type2":billboardData.Type2, "Rank":rank, "Index":index,
|
| | | "ID":billboardData.ID, "ID2":billboardData.ID2, |
| | | "Name1":billboardData.Name1, "Name2":billboardData.Name2,
|
| | | "Value1":billboardData.Value1, "Value2":billboardData.Value2,
|
| | | "Value3":billboardData.Value3, "Value4":billboardData.Value4,
|
| | |
| | | "Value7":billboardData.Value7, "Value8":billboardData.Value8,
|
| | | "CmpValue":billboardData.CmpValue, "CmpValue2":billboardData.CmpValue2,
|
| | | "CmpValue3":billboardData.CmpValue3, "UserData":billboardData.UserData}
|
| | | DataRecordPack.SendEventPack(eventTypeName, dataDict)
|
| | | DataRecordPack.SendEventPack(eventTypeStr, dataDict)
|
| | | return
|
| | |
|
| | | def GetBillboardDataList(self): return self.__billboardList
|
| | | def GetIDOrderDict(self):
|
| | | ## 获取ID对应名次字典
|
| | | # @return: {ID:名次, ...} 名次从1开始
|
| | | if not self.__idOrderDict:
|
| | | for order, billboardData in enumerate(self.__billboardList, 1):
|
| | | self.__idOrderDict[billboardData.ID] = order
|
| | | if not self.__idOrderDict or not self.__idIndexDict:
|
| | | self.__idOrderDict = {}
|
| | | self.__idIndexDict = {}
|
| | | if self.__orderRuleList:
|
| | | billboardDataCount = self.GetCount()
|
| | | rankPre = 0
|
| | | billboardIndex = 0
|
| | | for rank, needCmpValue in self.__orderRuleList:
|
| | | orderCountTotal = rank - rankPre # 奖励名次数量
|
| | | rankPre = rank
|
| | | for index in xrange(billboardIndex, billboardDataCount):
|
| | | if orderCountTotal <= 0:
|
| | | break
|
| | | billboardData = self.At(index)
|
| | | if billboardData.CmpValue < needCmpValue:
|
| | | break
|
| | | orderReal = rank - orderCountTotal + 1
|
| | | 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
|
| | |
| | | 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]:
|
| | | continue
|
| | | groupList = billboardMgr.GetBillboardGroupList(billboardType)
|
| | | for billboardType, groupValue1, groupValue2 in groupList:
|
| | | billboardObj = billboardMgr.GetCrossBillboard(billboardType, groupValue1, groupValue2)
|
| | | billboardObj.SaveDRData()
|
| | | billboardObj.SaveDRData("OnDay")
|
| | | return
|
| | |
|
| | | def OnMinuteProcess():
|
| | | billboardMgr = PyDataManager.GetCrossBillboardManager()
|
| | | for billboardType in ShareDefine.CrossBillboardTypeList:
|
| | | groupList = billboardMgr.GetBillboardGroupList(billboardType)
|
| | | for billboardType, groupValue1, groupValue2 in groupList:
|
| | | billboardObj = billboardMgr.GetCrossBillboard(billboardType, groupValue1, groupValue2)
|
| | | billboardObj.DoDelaySort()
|
| | | return
|
| | |
|
| | | def CopyBillboard(fromBillboardType, toBillboardType):
|
| | |
| | | queryData = {}
|
| | | billboardMgr = PyDataManager.GetCrossBillboardManager()
|
| | | 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}
|
| | |
| | | CmpValue = billboardData.CmpValue
|
| | | CmpValue2 = billboardData.CmpValue2
|
| | | CmpValue3 = billboardData.CmpValue3
|
| | | syncBillboardList.append([index, ID, ID2, Name1, Name2, Type2, Value1, Value2, CmpValue, CmpValue2, CmpValue3, Value3, Value4, Value5, Value6, Value7, Value8, UserData])
|
| | | orderIndex = idOrderDict.get(ID, index + 1) - 1
|
| | | syncBillboardList.append([orderIndex, ID, ID2, Name1, Name2, Type2, Value1, Value2, CmpValue, CmpValue2, CmpValue3, Value3, Value4, Value5, Value6, Value7, Value8, UserData])
|
| | | msgData["BillboardDataList"] = syncBillboardList
|
| | |
|
| | | CrossRealmMsg.SendMsgToClientServer(ShareDefine.CrossServerMsg_SyncBillboard, msgData, serverGroupIDList)
|
| | |
| | | billboardInfo.WatchID = watchID
|
| | | billboardInfo.CrossBillboardDataList = []
|
| | | for dataInfo in billboardList:
|
| | | index, ID, ID2, Name1, Name2, Type2, Value1, Value2, CmpValue, CmpValue2, CmpValue3, Value3, Value4, Value5, Value6, Value7, Value8, UserData = dataInfo
|
| | | orderIndex, ID, ID2, Name1, Name2, Type2, Value1, Value2, CmpValue, CmpValue2, CmpValue3, Value3, Value4, Value5, Value6, Value7, Value8, UserData = dataInfo
|
| | | billboardInfoData = ChPyNetSendPack.tagGCCrossBillboardData()
|
| | | billboardInfoData.OrderIndex = index
|
| | | billboardInfoData.OrderIndex = orderIndex
|
| | | billboardInfoData.ID = ID
|
| | | billboardInfoData.ID2 = ID2
|
| | | billboardInfoData.Name1 = Name1
|
| | |
| | | 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
|
| | |
| | | type2, value1, value2, cmpValue, cmpValue2, cmpValue3, kwargs), dataID)
|
| | | if noSortAndSync:
|
| | | return True
|
| | | if autoSort and cmpValueChange:
|
| | | |
| | | # 新数据可能导致榜单ID增减,强制排序一次
|
| | | if isNewData:
|
| | | billboardObj.SortData()
|
| | | elif cmpValueChange:
|
| | | if autoSort:
|
| | | billboardObj.SortData()
|
| | | else:
|
| | | billboardObj.SetDelaySort()
|
| | | else:
|
| | | billboardObj.UpdCrossServerDataVer()
|
| | | return True
|