| | |
| | | import PyDataManager
|
| | | import PlayerViewCache
|
| | | import IpyGameDataPY
|
| | | import PyGameData
|
| | |
|
| | | import time
|
| | | import random
|
| | |
| | | Def_NeedCopyYesterday_Dict = {
|
| | | #昨日榜(拷贝) #今日榜(源数据)
|
| | | }
|
| | |
|
| | | class BillboardObj(object):
|
| | | ''' 榜单额外数据管理
|
| | | '''
|
| | | |
| | | def __init__(self, billboardType):
|
| | | self.__billboardType = billboardType
|
| | | self.__idOrderDict = {} # {id:名次, ...}
|
| | | self.__orderRuleList = None
|
| | | return
|
| | | |
| | | def OnBillboardChange(self):
|
| | | ## 榜单数据变更
|
| | | self.__idOrderDict = {}
|
| | | return
|
| | | |
| | | def GetIDOrderDict(self):
|
| | | ## 获取ID对应名次字典,本服榜仅处理有特殊排名规则的
|
| | | # @return: {ID:名次, ...} 名次从1开始,如果返回空字典,则使用默认名次逻辑,即 index + 1
|
| | | if not self.__orderRuleList:
|
| | | return {}
|
| | | |
| | | if not self.__idOrderDict:
|
| | | billBoard = GameWorld.GetBillboard().FindBillboard(self.__billboardType)
|
| | | if not billBoard:
|
| | | return {}
|
| | | billboardDataCount = billBoard.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 = billBoard.At(index)
|
| | | if billboardData.GetCmpValue() < needCmpValue:
|
| | | break
|
| | | orderReal = rank - orderCountTotal + 1
|
| | | self.__idOrderDict[billboardData.GetID()] = orderReal
|
| | | orderCountTotal -= 1
|
| | | billboardIndex += 1
|
| | | return self.__idOrderDict
|
| | | |
| | | def SetOrderRuleList(self, orderRuleList):
|
| | | ## 排名所需值规则列表
|
| | | # @param orderRuleList: 排名所需值规则列表 [[order, needCmpValue], ...]
|
| | | self.__orderRuleList = orderRuleList
|
| | | self.__idOrderDict = {} # 设置后需重置,可能配置规则变化了导致实际排名可能变化
|
| | | GameWorld.Log("设置排名所需值规则列表: billboardType=%s, %s" % (self.__billboardType, orderRuleList))
|
| | | return
|
| | | |
| | | class BillboardMgr(object):
|
| | | ''' 榜单额外管理
|
| | | '''
|
| | | |
| | | def __init__(self):
|
| | | self.__billboardDict = {} # {榜单类型:Billboard, ...}
|
| | | return
|
| | | |
| | | def GetBillboardObj(self, billboardType):
|
| | | if billboardType in self.__billboardDict:
|
| | | billboard = self.__billboardDict[billboardType]
|
| | | else:
|
| | | billboard = BillboardObj(billboardType)
|
| | | self.__billboardDict[billboardType] = billboard
|
| | | return billboard
|
| | | |
| | | def GetBillboardMgr():
|
| | | if PyGameData.g_billboardMgrMgr:
|
| | | billMgr = PyGameData.g_billboardMgrMgr
|
| | | else:
|
| | | billMgr = BillboardMgr()
|
| | | PyGameData.g_billboardMgrMgr = billMgr
|
| | | return billMgr
|
| | |
|
| | | def NoteOssBillboardInfoByDay():
|
| | | ## 每天记录排行榜信息到oss中
|
| | |
| | | #if not __CheckWatchCD(curPlayer, packType, tick):
|
| | | # return
|
| | |
|
| | | if GameWorld.GetGameWorld().GetDictByKey(Def_Key_BillboardNeedSort % packType):
|
| | | GameWorld.GetGameWorld().SetDict(Def_Key_BillboardNeedSort % packType, 0)
|
| | | #GameWorld.DebugLog("玩家查看排行榜,强制排序!packType=%s" % (packType))
|
| | | SortBillboardByIndex(packType)
|
| | | |
| | | Sync_BillboardEx(curPlayer, packType, watchID, startIndex, watchCnt)
|
| | | return
|
| | |
|
| | |
| | | watchCnt = 20 if not watchCnt else min(watchCnt, 100) # 默认20,最多100
|
| | | endIndex = min(startIndex + watchCnt, count)
|
| | |
|
| | | billboardMgr = GetBillboardMgr()
|
| | | billboardObj = billboardMgr.GetBillboardObj(bbType)
|
| | | idOrderDict = billboardObj.GetIDOrderDict()
|
| | | |
| | | billBoardData = ChPyNetSendPack.tagPYBillboardData()
|
| | | billBoardData.Clear()
|
| | | billBoardData.WatchID = watchID
|
| | |
| | |
|
| | | bbInfo = ChPyNetSendPack.tagPYBillboardInfo()
|
| | | bbInfo.Clear()
|
| | | bbInfo.OrderIndex = index
|
| | | bbInfo.OrderIndex = idOrderDict.get(bbData.GetID(), index + 1) - 1
|
| | | bbInfo.ID = bbData.GetID()
|
| | | bbInfo.ID2 = bbData.GetID2()
|
| | | bbInfo.Name1 = bbData.GetName1()
|
| | |
| | | if not cmpValueChange:
|
| | | return True
|
| | |
|
| | | billboardMgr = GetBillboardMgr()
|
| | | billboardObj = billboardMgr.GetBillboardObj(billboardIndex)
|
| | | billboardObj.OnBillboardChange()
|
| | | |
| | | if not autoSort:
|
| | | #不自动排序
|
| | | GameWorld.GetGameWorld().SetDict(Def_Key_BillboardNeedSort % billboardIndex, 1) # 设置需要下次查看需要先排序
|