ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerBillboard.py
@@ -20,31 +20,30 @@
import GameWorld
import ChConfig
import ShareDefine
import ReadChConfig
import PlayerControl
import ChPyNetSendPack
import NetPackCommon
import PlayerDBGSEvent
import NetPackCommon
import DataRecordPack
import PlayerFamily
import PyDataManager
import PlayerViewCache
import IpyGameDataPY
import time
import random
Def_Key_BillboardSortTick = "BillboardSortTick_%s" # 排行榜是否排序tick,参数(排行榜类型)
Def_Key_BillboardNeedSort = "BillboardNeedSort_%s" # 排行榜是否需要排序,参数(排行榜类型)
#需要每天记录到oss的排行榜类型
Def_NoteOssBillboardTypeList = [
    ShareDefine.Def_BT_LV ,                  #个人等级日榜
    ShareDefine.Def_BT_FightPower,           #个人战斗力
                                ]
#需要每天拷贝昨日榜单的排行榜类型字典
Def_NeedCopyYesterday_Dict = {
    #昨日榜(拷贝)                                    #今日榜(源数据)
    ShareDefine.Def_BT_HighLadder_Yester     :  ShareDefine.Def_BT_HighLadder,
                         }
def NoteOssBillboardInfoByDay():
    ## 每天记录排行榜信息到oss中
    Def_NoteOssBillboardTypeList = IpyGameDataPY.GetFuncEvalCfg("BillboardSet", 1)
    for billboardType in Def_NoteOssBillboardTypeList:
        DataRecordPack.DR_BillboardDataByDay(billboardType)
    return
@@ -77,6 +76,30 @@
        
    return
def __CheckFightPowerBillboard():
    ## 由于战力修改为支持超过20E,所以需要处理下战力相关榜单,原 cmpValue 值移动到 cmpValue2
    eventKey = "FightPowerBillboardMoveValue"
    if PlayerDBGSEvent.GetDBGSTrig_ByKey(eventKey):
        return
    PlayerDBGSEvent.SetDBGSTrig_ByKey(eventKey, 1)
    GameWorld.Log("处理战力榜超过20E支持!")
    billboardList = [ShareDefine.Def_BT_FightPower] + ShareDefine.JobFightPowerBillboardDict.values()
    for billboardType in billboardList:
        billboard = GameWorld.GetBillboard().FindBillboard(billboardType)
        if not billboard:
            continue
        GameWorld.Log("    billboardType=%s,count=%s" % (billboardType, billboard.GetCount()))
        for index in xrange(billboard.GetCount()):
            billBoardData = billboard.At(index)
            if not billBoardData:
                continue
            billBoardData.SetCmpValue2(billBoardData.GetCmpValue())
            billBoardData.SetCmpValue(0)
    return
def SortServerBillboard():
    ##排序所有排行榜
    billboardMgr = GameWorld.GetBillboard()
@@ -85,7 +108,8 @@
        billBoard = billboardMgr.FindBillboard(index)
        #排序一次排行榜
        billBoard.Sort()
    __CheckFightPowerBillboard()
    return
def CopyBillboard(newBillboardIndex, oldBillboardIndex):
@@ -154,6 +178,33 @@
    GameWorld.Log('billboardIndex %s clear.'%billboardIndex)
    return
def UpdateBillboardMaxCount(billboardIndex, updMaxCount, isDelExtra=True):
    ''' 变更竞技场榜单最大数据数
    @param updMaxCount: 更新的最大数据排名
    @param isDelExtra: 是否删除原榜单排名数据超过更新后的最大排名,默认删除
    '''
    billBoard = GameWorld.GetBillboard().FindBillboard(billboardIndex)
    if not billBoard:
        return
    curCount = billBoard.GetCount()
    curMaxCount = billBoard.GetMaxCount()
    # 不超过程序内置配置的最大数量
    if billboardIndex in ChConfig.Def_BT_Cnt:
        updMaxCount = min(updMaxCount, ChConfig.Def_BT_Cnt[billboardIndex])
    if curMaxCount == updMaxCount:
        return
    billBoard.SetMaxCount(updMaxCount)
    GameWorld.Log("    变更榜单最大数据数! billboardIndex=%s,curCount=%s,curMaxCount=%s,updMaxCount=%s"
                  % (billboardIndex, curCount, curMaxCount, updMaxCount))
    # 清除多余榜单数据
    if isDelExtra and curCount > updMaxCount:
        for delIndex in xrange(curCount - 1, updMaxCount - 1, -1):
            if delIndex >= 0:
                GameWorld.Log("        DeleteByIndex: %s" % delIndex)
                billBoard.DeleteByIndex(delIndex)
    return
####################################################################################################
#class   IPY_GSetWatchBillboardState
@@ -215,6 +266,9 @@
    if packType in ChConfig.Def_InterdictLook_BT_Type:
        #不可通过此封包查看
        return
    if ChConfig.Def_BT_Cnt.get(packType, 0) > 100:
        GameWorld.DebugLog("该榜单最大名次较大,需使用分页查询! A9 A2 查看排行榜#tagCPYWatchBillboard")
        return
    if not __CheckWatchCD(curPlayer, packType, tick):
        return
@@ -390,7 +444,7 @@
def MapServer_UpdateBillboard(billInfoDict, tick):
    '''地图更新排行榜, 通用
    {"Type":bType, "Type2":bType2, "ID":bID, "ID2":bID2, "Name1":bName, "Name2":bName2, "ExInfo":exInfo,
    "Value1":value1, "Value2":value2, "CmpValue":cmpValue, "CmpValue2":cmpValue2, "CmpValue3":cmpValue3}
    "Value1":value1, "Value2":value2, "CmpValue":cmpValue, "CmpValue2":cmpValue2, "CmpValue3":cmpValue3, "autoSort":autoSort}
    '''
    
    bType = billInfoDict["Type"]
@@ -423,26 +477,24 @@
    
    gameWorld = GameWorld.GetGameWorld()
    lastSortTick = gameWorld.GetDictByKey(Def_Key_BillboardSortTick % bType)
    autoSort = (tick - lastSortTick) >= 60000 # 1分钟强制排序一次
    autoSort = (tick - lastSortTick) >= 60000 or billInfoDict.get("autoSort") == True # 1分钟强制排序一次
    if autoSort:
        gameWorld.SetDict(Def_Key_BillboardSortTick % bType, tick)
    #GameWorld.DebugLog("更新排行榜:bType=%s,autoSort=%s,tick=%s,lastSortTick=%s,d=%s" % (bType, autoSort, tick, lastSortTick, tick - lastSortTick))
    
    UpdatePlayerBillboard(bID, bName, bName2, bType, bType2, value1, value2, cmpValue, autoSort, cmpValue2, cmpValue3)
    gameWorld.SetDict(Def_Key_BillboardNeedSort % bType, 1)
    #__UpdateBillboardSortState(gameWorld, bType, autoSort, isUpd)
    
    exInfo = billInfoDict["ExInfo"]
    # 以下为榜单附加特殊处理
    if bType == ShareDefine.Def_BT_FightPower:
        playerID = bID
        fightPowerTotal = cmpValue
        fightPowerTotal = cmpValue * ChConfig.Def_PerPointValue + cmpValue2
        familyID = exInfo[0]
        playerJob = bType2
        
        curPlayer = GameWorld.GetPlayerManager().FindPlayerByID(playerID)
        if curPlayer:
            curPlayer.SetFightPower(fightPowerTotal)
            PlayerControl.SetFightPower(curPlayer, fightPowerTotal)
            
        #更新战盟成员战力
        PlayerFamily.UpdFamilyMemberFightPower(familyID, playerID, fightPowerTotal)
@@ -451,21 +503,78 @@
        job = playerJob % 10
        if job in ShareDefine.JobFightPowerBillboardDict:
            jobBType = ShareDefine.JobFightPowerBillboardDict[job]
            UpdatePlayerBillboard(bID, bName, bName2, jobBType, bType2, value1, value2, cmpValue, autoSort)
            gameWorld.SetDict(Def_Key_BillboardNeedSort % jobBType, 1)
            #__UpdateBillboardSortState(gameWorld, jobBType, autoSort, isUpd)
            UpdatePlayerBillboard(bID, bName, bName2, jobBType, bType2, value1, value2, cmpValue, autoSort, cmpValue2)
            
    return
def __UpdateBillboardSortState(gameWorld, bType, autoSort, isUpd):
    key = Def_Key_BillboardNeedSort % bType
    needSort = gameWorld.GetDictByKey(key)
    if not autoSort and isUpd and not needSort:
        gameWorld.SetDict(key, 1)
    elif autoSort and needSort:
        gameWorld.SetDict(key, 0)
def DelJobFightPowerBillboard(curPlayer, delJob):
    ## 删除玩家对应职业战力榜  - 一般是玩家职业改变了,需要删除旧职业的职业战力榜单
    if delJob not in ShareDefine.JobFightPowerBillboardDict:
        return
    jobBType = ShareDefine.JobFightPowerBillboardDict[delJob]
    playerID = curPlayer.GetPlayerID()
    billboardMgr = GameWorld.GetBillboard()
    playerBillBoard = billboardMgr.FindBillboard(jobBType)
    if not playerBillBoard:
        return
    if playerBillBoard.FindByID(playerID):
        playerBillBoard.DeleteByID(playerID)
        GameWorld.DebugLog("删除玩家职业战力榜单: delJob=%s,jobBType=%s" % (delJob, jobBType), playerID)
    return
def GetBillboardOperateInfo(curPlayer):
    # 排行榜中所保存的运营商相关信息
    return curPlayer.GetFace()
#    platform = curPlayer.GetAccID()
#    if platform in ["tencent"]:
#        return curPlayer.GetOperateInfo()
#    return platform
def UpdatePlayerBillboardEx(curPlayer, playerID, bType, cmpValue, cmpValue2=0, cmpValue3=0, value1=0, value2=0, autoSort=False):
    ## 更新玩家排行榜
    # @param curPlayer: 可能为None
    playerOpInfo = ""
    playerJob = 0
    playerName = ""
    playerRealmLV = 0
    if curPlayer:
        playerID = curPlayer.GetID()
        playerJob = curPlayer.GetJob()
        playerName = curPlayer.GetName()
        playerRealmLV = curPlayer.GetOfficialRank()
        playerOpInfo = GetBillboardOperateInfo(curPlayer)
    else:
        socialPlayer = PyDataManager.GetPersonalSocialManager().GetSocialPlayer(playerID)
        if socialPlayer:
            playerJob = socialPlayer.playerInfo.Job
            playerName = socialPlayer.playerInfo.PlayerName
            playerRealmLV = socialPlayer.playerInfo.RealmLV
        else:
            curCache = PlayerViewCache.FindViewCache(playerID)
            if curCache:
                cacheDict = PlayerViewCache.GetCachePropDataDict(curCache)
                playerJob = cacheDict["Job"]
                playerName = cacheDict["Name"]
                playerRealmLV = cacheDict["RealmLV"]
    if not playerName and playerID < 10000:
        playerJob = random.choice([1, 2])
        playerName = "testName%s" % playerID
        playerRealmLV = random.randint(1, 10)
        
    #GameWorld.DebugLog("__UpdateBillboardSortState:bType=%s,autoSort=%s,isUpd=%s,needSort=%s" % (bType, autoSort, isUpd, gameWorld.GetDictByKey(key)))
    if bType in ShareDefine.BTValue1_OfficialRankList:
        value1 = playerRealmLV
    tick = GameWorld.GetGameWorld().GetTick()
    gameWorld = GameWorld.GetGameWorld()
    lastSortTick = gameWorld.GetDictByKey(Def_Key_BillboardSortTick % bType)
    autoSort = ((tick - lastSortTick) >= 60000 or autoSort) # 1分钟强制排序一次
    if autoSort:
        gameWorld.SetDict(Def_Key_BillboardSortTick % bType, tick)
    UpdatePlayerBillboard(playerID, playerName, playerOpInfo, bType, playerJob, value1, value2, cmpValue, autoSort, cmpValue2, cmpValue3)
    return
#---------------------------------------------------------------------
@@ -520,6 +629,9 @@
        if opInfo != str(curPlayerOpInfo):
            playerBillBoardData.SetName2(str(curPlayerOpInfo))
            GameWorld.DebugLog("    更新operatInfo=%s" % curPlayerOpInfo, curPlayerID)
        if playerBillBoardData.GetType2() != billboardType:
            playerBillBoardData.SetType2(billboardType)
            GameWorld.DebugLog("    更新Type2=%s" % billboardType, curPlayerID)
        return False
    
    # 没设置值默认为时间time,先上榜的排前面
@@ -550,6 +662,7 @@
                       % (billboardIndex, billboardType, value1, value2, cmpValue, cmpValue2, cmpValue3, isNewData), curPlayerID)
    if not autoSort:
        #不自动排序
        GameWorld.GetGameWorld().SetDict(Def_Key_BillboardNeedSort % billboardIndex, 1) # 设置需要下次查看需要先排序
        return True
    
    #重新排序排行榜
@@ -652,89 +765,10 @@
def ViewBillboardRangeByObjID(index, clientData, tick):
    return
## 更新充值特惠排行榜
#  @param cmdList
#  @return None
def MapServer_UpdateRechargeRankBillboard(cmdList):
    playerID, playerName, playerOpInfo, playerJob, playerLV, familyName, actionID, actionNum, updateGold = cmdList
    # 排行榜上榜限制
    RechargeRankInfoDict = ReadChConfig.GetEvalChConfig("TeHuiAction_RechargeRank")
    gameWorld = GameWorld.GetGameWorld()
    actionNumKey = ShareDefine.Def_Notify_WorldKey_DayAction_RechargeRank
    curActionNum = gameWorld.GetDictByKey(actionNumKey)
    curActionID = gameWorld.GetDictByKey(ShareDefine.Def_Notify_WorldKey_DayAction_ID % actionNumKey)
    GameWorld.DebugLog("MapServer_UpdateRechargeRankBillboard...")
    GameWorld.DebugLog("    actionID=%s,actionNum=%s,updateGold=%s,curActionID=%s,curActionNum=%s,"
                       % (actionID, actionNum, updateGold, curActionID, curActionNum), playerID)
    # 非当前活动,不更新
    if actionNum not in RechargeRankInfoDict or actionNum != curActionNum or actionID != curActionID:
        GameWorld.DebugLog("    非当前充值特惠排行榜活动,不更新...", playerID)
        return
    rechargeRankInfoList = RechargeRankInfoDict[actionNum]
    if len(rechargeRankInfoList) <= 0:
        return
    limitGold = rechargeRankInfoList[0] # 限制上榜充值数
    if updateGold < limitGold:
        GameWorld.DebugLog("    未达到最低上榜充值数=%s,不更新..." % limitGold, playerID)
        return
    #排行榜
    cmpValue = updateGold
    isOk = UpdatePlayerBillboard(playerID, playerName, familyName, ShareDefine.Def_BT_RechargeTeHui,
                                 playerJob, playerLV, updateGold, cmpValue)
    GameWorld.DebugLog("    更新充值特惠排行榜 isOk=%s" % isOk, playerID)
    return
## 更新消费特惠排行榜
#  @param cmdList
#  @return None
def MapServer_UpdateCostRankBillboard(cmdList):
    playerID, playerName, playerOpInfo, playerJob, playerLV, familyName, actionID, actionNum, updateGold = cmdList
    # 排行榜上榜限制
    costRankInfoDict = ReadChConfig.GetEvalChConfig("TeHuiAction_CostRank")
    gameWorld = GameWorld.GetGameWorld()
    actionNumKey = ShareDefine.Def_Notify_WorldKey_DayAction_CostRank
    curActionNum = gameWorld.GetDictByKey(actionNumKey)
    curActionID = gameWorld.GetDictByKey(ShareDefine.Def_Notify_WorldKey_DayAction_ID % actionNumKey)
    GameWorld.DebugLog("MapServer_UpdateCostRankBillboard...")
    GameWorld.DebugLog("    actionID=%s,actionNum=%s,updateGold=%s,curActionID=%s,curActionNum=%s,"
                       % (actionID, actionNum, updateGold, curActionID, curActionNum), playerID)
    # 非当前活动,不更新
    if actionNum not in costRankInfoDict or actionNum != curActionNum or actionID != curActionID:
        GameWorld.DebugLog("    非当前消费特惠排行榜活动,不更新...", playerID)
        return
    costRankInfoList = costRankInfoDict[actionNum]
    if len(costRankInfoList) <= 0:
        return
    limitGold = costRankInfoList[0] # 限制上榜消费数
    if updateGold < limitGold:
        GameWorld.DebugLog("    未达到最低上榜消费数=%s,不更新..." % limitGold, playerID)
        return
    #排行榜
    cmpValue = updateGold
    isOk = UpdatePlayerBillboard(playerID, playerName, familyName, ShareDefine.Def_BT_CostTeHui,
                                 playerJob, playerLV, 0, cmpValue)
    GameWorld.DebugLog("    更新消费特惠排行榜 isOk=%s" % isOk, playerID)
    return
## 排行榜更新是否受等级限制
def IsBillboardLVLimit(playerLV, billboardType):
    # 等级判断已由地图处理掉,这里不再做判断
    return True
#    BillBoardLimitInfo = ReadChConfig.GetEvalChConfig("BillBoardLimit")
#    defaultMinLV, limitLVDict = BillBoardLimitInfo
#    lvBillBoardMinLV = limitLVDict.get(billboardType, defaultMinLV)
#    if playerLV < lvBillBoardMinLV:
#        return True
#
#    return False
def RedressBillboard(curPlayer):
    ## 纠正排行榜中的玩家名字记录
@@ -793,3 +827,24 @@
        
    return
def UpdateBillboardFace(curPlayer):
    ## 更新排行榜中的玩家头像
    curPlayerID = curPlayer.GetID()
    curFace = curPlayer.GetFace()
    billboardMgr = GameWorld.GetBillboard()
    for billboardIndex in ShareDefine.BillboardTypeList:
        billBoard = billboardMgr.FindBillboard(billboardIndex)
        if not billBoard:
            #找不到这类型排行榜
            continue
        playerBillBoardData = billBoard.FindByID(curPlayerID)
        if not playerBillBoardData:
            #该玩家没有在排行榜上
            continue
        playerBillBoardData.SetName2(str(curFace))
    return