#!/usr/bin/python  
 | 
# -*- coding: GBK -*-  
 | 
#-------------------------------------------------------------------------------  
 | 
#  
 | 
##@package CrossActAllRecharge  
 | 
#  
 | 
# @todo:¿ç·þÈ«Ãñ³äÖµ  
 | 
# @author hxp  
 | 
# @date 2022-10-11  
 | 
# @version 1.0  
 | 
#  
 | 
# ÏêϸÃèÊö: ¿ç·þÈ«Ãñ³äÖµ  
 | 
#  
 | 
#-------------------------------------------------------------------------------  
 | 
#"""Version = 2022-10-11 19:00"""  
 | 
#-------------------------------------------------------------------------------  
 | 
  
 | 
import PyGameData  
 | 
import ShareDefine  
 | 
import CrossRealmMsg  
 | 
import DataRecordPack  
 | 
import CrossActionControl  
 | 
import ChPyNetSendPack  
 | 
import NetPackCommon  
 | 
import IpyGameDataPY  
 | 
import GameWorld  
 | 
  
 | 
Def_RecType_CrossActAllRecharge = ShareDefine.Def_UniversalGameRecType_CrossActAllRecharge  
 | 
'''  
 | 
¿ç·þÈ«Ãñ³äÖµ»î¶¯ÐÅÏ¢  
 | 
ShareDefine.Def_UniversalGameRecType_CrossActAllRecharge  
 | 
value1:zoneID            ·ÖÇøID  
 | 
value2:playerID         Íæ¼ÒID  
 | 
value3:totalRMB        ×ܳäÖµ  
 | 
value4:cfgID            cfgID  
 | 
StrValue3:                Õ˺Š 
 | 
'''  
 | 
def GetRecZoneID(recData): return recData.GetValue1()  
 | 
def SetRecZoneID(recData, zoneID): return recData.SetValue1(zoneID)  
 | 
def GetRecPlayerID(recData): return recData.GetValue2()  
 | 
def SetRecPlayerID(recData, playerID): return recData.SetValue2(playerID)  
 | 
def GetRecTotalRecharge(recData): return recData.GetValue3()  
 | 
def SetRecTotalRecharge(recData, totalRMB): return recData.SetValue3(totalRMB)  
 | 
def GetRecCfgID(recData): return recData.GetValue4()  
 | 
def SetRecCfgID(recData, cfgID): return recData.SetValue4(cfgID)  
 | 
def GetRecAccID(recData): return recData.GetStrValue3()  
 | 
def SetRecAccID(recData, accID): return recData.SetStrValue3(accID)  
 | 
  
 | 
  
 | 
def OnPlayerLogin(curPlayer):  
 | 
    if GameWorld.IsCrossServer():  
 | 
        return  
 | 
    Sync_CrossActAllRechargeInfo(curPlayer)  
 | 
    return  
 | 
  
 | 
def Sync_AllRechargeDataToClientServer(serverGroupID=0):  
 | 
    GameWorld.Log("ͬ²½¸ø×Ó·þ¶ÔÓ¦µÄ¿ç·þÈ«Ãñ³äÖµÐÅÏ¢: syncServerGroupID=%s" % (serverGroupID))  
 | 
      
 | 
    allRechargeInfo = {} # È«Ãñ³äÖµÐÅÏ¢  
 | 
    universalRecMgr = GameWorld.GetUniversalRecMgr()  
 | 
    recDataList = universalRecMgr.GetTypeList(Def_RecType_CrossActAllRecharge)  
 | 
    for index in range(recDataList.Count()):  
 | 
        recData = recDataList.At(index)  
 | 
        cfgID = GetRecCfgID(recData)  
 | 
        zoneID = GetRecZoneID(recData)  
 | 
        playerID = GetRecPlayerID(recData)  
 | 
        totalRecharge = GetRecTotalRecharge(recData)  
 | 
          
 | 
        key = (cfgID, zoneID)  
 | 
        if key not in allRechargeInfo:  
 | 
            allRechargeInfo[key] = {}  
 | 
        zoneInfo = allRechargeInfo[key]  
 | 
        zoneInfo[playerID] = totalRecharge  
 | 
          
 | 
    dataMsg = {"syncType":"All", "allRechargeInfo":allRechargeInfo}  
 | 
    CrossRealmMsg.SendMsgToClientServer(ShareDefine.CrossServerMsg_ActAllRechargeInfo, dataMsg)  
 | 
    return  
 | 
  
 | 
def OnActIDChange(ipyData, state):  
 | 
    ## »î¶¯×´Ì¬±ä¸ü  
 | 
      
 | 
    cfgID = ipyData.GetCfgID()  
 | 
    zoneID = ipyData.GetZoneID()  
 | 
      
 | 
    if not state:  
 | 
        actDataInfo = {}  
 | 
        universalRecMgr = GameWorld.GetUniversalRecMgr()  
 | 
        recDataList = universalRecMgr.GetTypeList(Def_RecType_CrossActAllRecharge)  
 | 
        for index in range(recDataList.Count()):  
 | 
            recData = recDataList.At(index)  
 | 
            recCfgID = GetRecCfgID(recData)  
 | 
            recZoneID = GetRecZoneID(recData)  
 | 
            if recCfgID != cfgID or recZoneID != zoneID:  
 | 
                continue  
 | 
              
 | 
            playerID = GetRecPlayerID(recData)  
 | 
            totalRecharge = GetRecTotalRecharge(recData)  
 | 
            accID = GetRecAccID(recData)  
 | 
              
 | 
            key = (recCfgID, recZoneID)  
 | 
            if key not in actDataInfo:  
 | 
                actDataInfo[key] = []  
 | 
            zoneDataList = actDataInfo[key]  
 | 
            zoneDataList.append([totalRecharge, playerID, accID])  
 | 
              
 | 
        # Êä³öÁ÷Ïò  
 | 
        for key, zoneDataList in actDataInfo.items():  
 | 
            recCfgID, recZoneID = key  
 | 
            zoneDataList.sort(reverse=True)  
 | 
            GameWorld.Log("¿ç·þÈ«Ãñ³äÖµ»î¶¯½áÊø! CfgID=%s,ZoneID=%s,DataCount=%s" % (recCfgID, recZoneID, len(zoneDataList)))  
 | 
            for dataInfo in zoneDataList:  
 | 
                totalRecharge, playerID, accID = dataInfo  
 | 
                drDataDict = {"CfgID":recCfgID, "ZoneID":recZoneID, "TotalRecharge":totalRecharge, "PlayerID":playerID, "AccID":accID}  
 | 
                DataRecordPack.SendEventPack("CrossActAllRecharge", drDataDict)  
 | 
                  
 | 
        return  
 | 
      
 | 
    universalRecMgr = GameWorld.GetUniversalRecMgr()  
 | 
    recDataList = universalRecMgr.GetTypeList(Def_RecType_CrossActAllRecharge)  
 | 
    delDataCount = 0  
 | 
    for index in range(recDataList.Count())[::-1]:  
 | 
        recData = recDataList.At(index)  
 | 
        recZoneID = GetRecZoneID(recData)  
 | 
        if recZoneID != zoneID:  
 | 
            continue  
 | 
        recDataList.Delete(index)  
 | 
        delDataCount += 1  
 | 
          
 | 
    GameWorld.Log("ÖØÖÿç·þÈ«Ãñ³äÖµ»î¶¯ÐÅÏ¢! cfgID=%s,ZoneID=%s,DataCount=%s" % (cfgID, zoneID, delDataCount))  
 | 
    dataMsg = {"syncType":"New", "cfgID":cfgID, "zoneID":zoneID}  
 | 
    CrossRealmMsg.SendMsgToClientServer(ShareDefine.CrossServerMsg_ActAllRechargeInfo, dataMsg)  
 | 
    return  
 | 
  
 | 
def ClientServerMsg_ActAllRechargeValue(serverGroupID, msgData):  
 | 
    ## ÊÕµ½×Ó·þͬ²½ÐÅÏ¢  - Íæ¼Ò³äÖµ¶î¶È  
 | 
      
 | 
    cfgID = msgData["cfgID"]  
 | 
    zoneID = msgData["zoneID"]  
 | 
    playerID = msgData["playerID"]  
 | 
    totalRMB = msgData["totalRMB"]  
 | 
    accID = msgData["accID"]  
 | 
      
 | 
    crossActInfoDict = CrossActionControl.GetCrossActInfoDict()  
 | 
    curActInfoDict = crossActInfoDict.get(ShareDefine.CrossActName_AllRecharge, {})  
 | 
    if cfgID not in curActInfoDict:  
 | 
        return  
 | 
    actInfo = curActInfoDict[cfgID]  
 | 
    if not actInfo[ShareDefine.ActKey_State]:  
 | 
        return  
 | 
    ipyDataDict = actInfo.get(ShareDefine.ActKey_IpyDataInfo, {})  
 | 
    if not ipyDataDict:  
 | 
        return  
 | 
    ipyZoneID = ipyDataDict.get("ZoneID", 0)  
 | 
    if zoneID != ipyZoneID:  
 | 
        return  
 | 
      
 | 
    findRec = None  
 | 
    universalRecMgr = GameWorld.GetUniversalRecMgr()  
 | 
    recDataList = universalRecMgr.GetTypeList(Def_RecType_CrossActAllRecharge)  
 | 
    for index in range(recDataList.Count()):  
 | 
        recData = recDataList.At(index)  
 | 
        recCfgID = GetRecCfgID(recData)  
 | 
        recZoneID = GetRecZoneID(recData)  
 | 
        recPlayerID = GetRecPlayerID(recData)  
 | 
        if recCfgID != cfgID or recZoneID != zoneID or recPlayerID != playerID:  
 | 
            continue  
 | 
        findRec = recData  
 | 
        totalRMBBefore = GetRecTotalRecharge(recData)  
 | 
        SetRecTotalRecharge(recData, totalRMB)  
 | 
        GameWorld.Log("¿ç·þÈ«Ãñ³äÖµÍæ¼Ò³äÖµ¶î¶È¸üÐÂ: cfgID=%s,zoneID=%s,totalRMBBefore=%s,totalRMB=%s,accID=%s"   
 | 
                      % (cfgID, zoneID, totalRMBBefore, totalRMB, accID), playerID)  
 | 
        break  
 | 
      
 | 
    if not findRec:  
 | 
        recData = recDataList.AddRec()  
 | 
        SetRecZoneID(recData, zoneID)  
 | 
        SetRecPlayerID(recData, playerID)  
 | 
        SetRecTotalRecharge(recData, totalRMB)  
 | 
        SetRecCfgID(recData, cfgID)  
 | 
        SetRecAccID(recData, accID)  
 | 
        GameWorld.Log("¿ç·þÈ«Ãñ³äÖµÍæ¼Ò³äÖµ¶î¶ÈÐÂÔö: cfgID=%s,zoneID=%s,totalRMB=%s,accID=%s"   
 | 
                      % (cfgID, zoneID, totalRMB, accID), playerID)  
 | 
          
 | 
    dataMsg = {"syncType":"PlayerAllRechargeValue", "cfgID":cfgID, "zoneID":zoneID, "playerID":playerID,   
 | 
               "totalRMB":totalRMB, "accID":accID}  
 | 
    CrossRealmMsg.SendMsgToClientServer(ShareDefine.CrossServerMsg_ActAllRechargeInfo, dataMsg)  
 | 
    return  
 | 
  
 | 
def CrossServerMsg_ActAllRechargeInfo(msgData):  
 | 
      
 | 
    syncType = msgData.get("syncType")  
 | 
      
 | 
    # ËùÓÐÊý¾Ýͬ²½  
 | 
    if syncType == "All":  
 | 
        allRechargeInfo = msgData["allRechargeInfo"]  
 | 
        for key, zoneInfo in allRechargeInfo.items():  
 | 
            PyGameData.g_crossActAllRechargeInfo[key] = zoneInfo  
 | 
            Sync_CrossActAllRechargeInfo(syncKey=key)  
 | 
        return  
 | 
      
 | 
    # Ð»  
 | 
    if syncType == "New":  
 | 
        cfgID = msgData["cfgID"]  
 | 
        zoneID = msgData["zoneID"]  
 | 
        for key in PyGameData.g_crossActAllRechargeInfo.keys():  
 | 
            if zoneID == key[1]:  
 | 
                PyGameData.g_crossActAllRechargeInfo.pop(key)  
 | 
        newKey = (cfgID, zoneID)  
 | 
        PyGameData.g_crossActAllRechargeInfo[newKey] = {}  
 | 
        Sync_CrossActAllRechargeInfo(syncKey=newKey)  
 | 
        return  
 | 
      
 | 
    # Íæ¼Ò³äÖµ×ܶî¸üР 
 | 
    if syncType == "PlayerAllRechargeValue":  
 | 
        cfgID = msgData["cfgID"]  
 | 
        zoneID = msgData["zoneID"]   
 | 
        playerID = msgData["playerID"]  
 | 
        totalRMB = msgData["totalRMB"]   
 | 
        #accID = msgData["accID"]  
 | 
        key = (cfgID, zoneID)  
 | 
        if key not in PyGameData.g_crossActAllRechargeInfo:  
 | 
            PyGameData.g_crossActAllRechargeInfo[key] = {}  
 | 
        zoneInfo = PyGameData.g_crossActAllRechargeInfo[key]  
 | 
        playerRMB = zoneInfo.get(playerID, 0)  
 | 
        zoneInfo[playerID] = totalRMB  
 | 
          
 | 
        actInfoDict = PyGameData.g_crossActInfoDict.get(ShareDefine.CrossActName_AllRecharge, {})  
 | 
        actInfo = actInfoDict.get(cfgID, {})  
 | 
        state = actInfo.get(ShareDefine.ActKey_State, 0)  
 | 
        ipyDataDict = actInfo.get(ShareDefine.ActKey_IpyDataInfo, {})  
 | 
        if not state or zoneID != ipyDataDict.get("ZoneID"):  
 | 
            return  
 | 
        templateID = actInfo.get(ShareDefine.ActKey_TemplateID, 0)  
 | 
        ipyDataList = IpyGameDataPY.GetIpyGameDataList("CrossActAllRechargeTemplate", templateID)  
 | 
        if not ipyDataList:  
 | 
            return  
 | 
          
 | 
        isSync = False  
 | 
        for ipyData in ipyDataList:  
 | 
            needRMB = ipyData.GetCTGNeed()  
 | 
            if playerRMB < needRMB and totalRMB >= needRMB:  
 | 
                isSync = True  
 | 
                break  
 | 
              
 | 
        if isSync:  
 | 
            Sync_CrossActAllRechargeInfo(syncKey=key)  
 | 
              
 | 
        return  
 | 
      
 | 
    return  
 | 
  
 | 
  
 | 
def MapServer_CrossActAllRecharge(curPlayer, msgList):  
 | 
    ##   
 | 
      
 | 
    playerID = curPlayer.GetPlayerID()  
 | 
    msgType = msgList[0]  
 | 
    msgData = msgList[1]  
 | 
      
 | 
    if msgType == "AllRechargeRMB":  
 | 
        cfgID, zoneID, totalRMB = msgData  
 | 
        actInfo = CrossActionControl.GetPlayerCrossActInfo(curPlayer, ShareDefine.CrossActName_AllRecharge)  
 | 
        if not actInfo.get(ShareDefine.ActKey_State):  
 | 
            return  
 | 
        key = (cfgID, zoneID)  
 | 
        zoneInfo = PyGameData.g_crossActAllRechargeInfo.get(key, {})  
 | 
        playerRMB = zoneInfo.get(playerID, 0)  
 | 
        if playerRMB == totalRMB:  
 | 
            return  
 | 
          
 | 
        # Í¬²½¿ç·þ·þÎñÆ÷  
 | 
        dataMsg = {"cfgID":cfgID, "zoneID":zoneID, "playerID":playerID, "totalRMB":totalRMB, "accID":curPlayer.GetAccID()}  
 | 
        CrossRealmMsg.SendMsgToCrossServer(ShareDefine.ClientServerMsg_ActAllRechargeValue, dataMsg)  
 | 
          
 | 
    if msgType == "AllRechargeAward":  
 | 
        cfgID, zoneID, awardIndex = msgData  
 | 
        GameWorld.Log("¿ç·þÈ«Ãñ³äÖµÍæ¼ÒÁì½±: cfgID=%s,zoneID=%s,awardIndex=%s" % (cfgID, zoneID, awardIndex), playerID)  
 | 
        actInfo = CrossActionControl.GetPlayerCrossActInfo(curPlayer, ShareDefine.CrossActName_AllRecharge)  
 | 
        if not actInfo.get(ShareDefine.ActKey_State):  
 | 
            return  
 | 
          
 | 
        templateID = actInfo.get(ShareDefine.ActKey_TemplateID, 0)  
 | 
        ipyDataList = IpyGameDataPY.GetIpyGameDataList("CrossActAllRechargeTemplate", templateID)  
 | 
        if not ipyDataList:  
 | 
            return  
 | 
          
 | 
        zoneInfo = PyGameData.g_crossActAllRechargeInfo.get((cfgID, zoneID), {})  
 | 
        for ipyData in ipyDataList:  
 | 
            if awardIndex != ipyData.GetAwardIndex():  
 | 
                continue  
 | 
            ctgNeed = ipyData.GetCTGNeed()  
 | 
            needPlayerCount = ipyData.GetNeedPlayerCount()  
 | 
            nowPlayerCount = 0  
 | 
            for totalRMB in zoneInfo.values():  
 | 
                if totalRMB >= ctgNeed:  
 | 
                    nowPlayerCount += 1  
 | 
                      
 | 
            if nowPlayerCount < needPlayerCount:  
 | 
                GameWorld.Log("ËùÐèÈ«Ãñ³äÖµÍæ¼ÒÊý²»×㣬ÎÞ·¨Áì½±: cfgID=%s,zoneID=%s,awardIndex=%s,ctgNeed=%s,nowPlayerCount=%s < %s"   
 | 
                              % (cfgID, zoneID, awardIndex, ctgNeed, nowPlayerCount, needPlayerCount), playerID)  
 | 
                return  
 | 
              
 | 
            awardItemList = ipyData.GetAwardItemList()  
 | 
            sysMsg = str([msgType, awardIndex, awardItemList])  
 | 
            curPlayer.MapServer_QueryPlayerResult(0, 0, "CrossActAllRecharge", sysMsg, len(sysMsg))  
 | 
            return  
 | 
          
 | 
    return  
 | 
  
 | 
  
 | 
def Sync_CrossActAllRechargeInfo(curPlayer=None, syncKey=None):  
 | 
    ## Í¨Öª»î¶¯ÐÅÏ¢  
 | 
      
 | 
    if PyGameData.g_crossActInfoDict == None:  
 | 
        return  
 | 
      
 | 
    if curPlayer:  
 | 
        actInfo = CrossActionControl.GetPlayerCrossActInfo(curPlayer, ShareDefine.CrossActName_AllRecharge)  
 | 
        # »î¶¯ÖÐͬ²½»î¶¯ÐÅÏ¢  
 | 
        if not actInfo.get(ShareDefine.ActKey_State):  
 | 
            return  
 | 
        cfgID = actInfo.get(ShareDefine.ActKey_CfgID)  
 | 
        ipyDataDict = actInfo.get(ShareDefine.ActKey_IpyDataInfo, {})  
 | 
        if not ipyDataDict:  
 | 
            return  
 | 
        zoneID = ipyDataDict.get("ZoneID")  
 | 
        if not cfgID or not zoneID:  
 | 
            return  
 | 
          
 | 
    elif syncKey and len(syncKey) == 2:  
 | 
        cfgID, zoneID = syncKey  
 | 
        actInfoDict = PyGameData.g_crossActInfoDict.get(ShareDefine.CrossActName_AllRecharge, {})  
 | 
        if not actInfoDict:  
 | 
            return  
 | 
        actInfo = actInfoDict.get(cfgID, {})  
 | 
        if not actInfo:  
 | 
            return  
 | 
        if not actInfo.get(ShareDefine.ActKey_State, 0):  
 | 
            return  
 | 
        ipyDataDict = actInfo.get(ShareDefine.ActKey_IpyDataInfo, {})  
 | 
        if not ipyDataDict:  
 | 
            return  
 | 
        if not cfgID or zoneID != ipyDataDict.get("ZoneID"):  
 | 
            return  
 | 
    else:  
 | 
        return  
 | 
      
 | 
    templateID = actInfo.get(ShareDefine.ActKey_TemplateID, 0)  
 | 
    ipyDataList = IpyGameDataPY.GetIpyGameDataList("CrossActAllRechargeTemplate", templateID)  
 | 
    if not ipyDataList:  
 | 
        return  
 | 
      
 | 
    zoneInfo = PyGameData.g_crossActAllRechargeInfo.get((cfgID, zoneID), {})  
 | 
      
 | 
    actPack = ChPyNetSendPack.tagGCCrossActAllRechargeInfo()  
 | 
    actPack.ServerIDRangeInfo = str(actInfo.get(ShareDefine.ActKey_ServerIDRangeList, []))  
 | 
    actPack.ServerInfoLen = len(actPack.ServerIDRangeInfo)  
 | 
    actPack.StartDate = ipyDataDict.get("StartDate", "")  
 | 
    actPack.EndtDate = ipyDataDict.get("EndDate", "")  
 | 
    actPack.AwardList = []  
 | 
      
 | 
    for ipyData in ipyDataList:  
 | 
        award = ChPyNetSendPack.tagGCCrossActAllRechargeAward()  
 | 
        award.AwardIndex = ipyData.GetAwardIndex()  
 | 
        award.NeedRMB = ipyData.GetCTGNeed()  
 | 
        award.NeedPlayerCount = ipyData.GetNeedPlayerCount()  
 | 
        award.AwardItemList = []  
 | 
        for itemID, itemCount, isAuctionItem in ipyData.GetAwardItemList():  
 | 
            item = ChPyNetSendPack.tagGCCrossActAllRechargeItem()  
 | 
            item.ItemID = itemID  
 | 
            item.ItemCount = itemCount  
 | 
            item.IsBind = isAuctionItem  
 | 
            award.AwardItemList.append(item)  
 | 
        award.AwardItemCount = len(award.AwardItemList)  
 | 
          
 | 
        nowPlayerCount = 0  
 | 
        for totalRMB in zoneInfo.values():  
 | 
            if totalRMB >= ipyData.GetCTGNeed():  
 | 
                nowPlayerCount += 1  
 | 
        award.NowPlayerCount = nowPlayerCount  
 | 
          
 | 
        actPack.AwardList.append(award)  
 | 
    actPack.AwardCount = len(actPack.AwardList)  
 | 
      
 | 
    if curPlayer:  
 | 
        NetPackCommon.SendFakePack(curPlayer, actPack)  
 | 
    else:  
 | 
        playerManager = GameWorld.GetPlayerManager()  
 | 
        for i in xrange(playerManager.GetActivePlayerCount()):  
 | 
            curPlayer = playerManager.GetActivePlayerAt(i)  
 | 
            if curPlayer == None or not curPlayer.GetInitOK():  
 | 
                continue  
 | 
              
 | 
            actInfo = CrossActionControl.GetPlayerCrossActInfo(curPlayer, ShareDefine.CrossActName_AllRecharge)  
 | 
            state = actInfo.get(ShareDefine.ActKey_State)  
 | 
            pCfgID = actInfo.get(ShareDefine.ActKey_CfgID)  
 | 
            ipyDataDict = actInfo.get(ShareDefine.ActKey_IpyDataInfo, {})  
 | 
            pZoneID = ipyDataDict.get("ZoneID")  
 | 
            if not state or pCfgID != cfgID or pZoneID != zoneID:  
 | 
                continue  
 | 
              
 | 
            NetPackCommon.SendFakePack(curPlayer, actPack)  
 | 
              
 | 
    return  
 | 
  
 | 
  
 | 
  
 | 
  
 |