#!/usr/bin/python  
 | 
# -*- coding: GBK -*-  
 | 
#-------------------------------------------------------------------------------  
 | 
#  
 | 
##@package Player.PlayerActGrowupBuy  
 | 
#  
 | 
# @todo:ÔËÓª»î¶¯ - ³É³¤±ØÂò  
 | 
# @author hxp  
 | 
# @date 2020-11-23  
 | 
# @version 1.0  
 | 
#  
 | 
# ÏêϸÃèÊö: ÔËÓª»î¶¯ - ³É³¤±ØÂò  
 | 
#  
 | 
#-------------------------------------------------------------------------------  
 | 
#"""Version = 2020-11-23 21:00"""  
 | 
#-------------------------------------------------------------------------------  
 | 
  
 | 
  
 | 
import PyGameData  
 | 
import ShareDefine  
 | 
import PlayerControl  
 | 
import IpyGameDataPY  
 | 
import ChPyNetSendPack  
 | 
import NetPackCommon  
 | 
import GameWorld  
 | 
import ChConfig  
 | 
  
 | 
def OnPlayerLogin(curPlayer):  
 | 
    isReset = __CheckPlayerGrowupBuyAction(curPlayer)  
 | 
    if not isReset:  
 | 
        actInfo = PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_GrowupBuy, {})  
 | 
        # »î¶¯ÖÐͬ²½»î¶¯ÐÅÏ¢  
 | 
        if actInfo.get(ShareDefine.ActKey_State):  
 | 
            Sync_GrowupActionInfo(curPlayer)  
 | 
    return  
 | 
  
 | 
def RefreshGrowupBuyActionInfo():  
 | 
    ## ÊÕµ½GameServerͬ²½µÄ»î¶¯ÐÅÏ¢£¬Ë¢Ð»ÐÅÏ¢  
 | 
    playerManager = GameWorld.GetPlayerManager()  
 | 
    for index in xrange(playerManager.GetPlayerCount()):  
 | 
        curPlayer = playerManager.GetPlayerByIndex(index)  
 | 
        if curPlayer.GetID() == 0:  
 | 
            continue  
 | 
        __CheckPlayerGrowupBuyAction(curPlayer)  
 | 
    return  
 | 
  
 | 
def __CheckPlayerGrowupBuyAction(curPlayer):  
 | 
    ## ¼ì²éÍæ¼Ò³äÖµ·µÀû»î¶¯Êý¾ÝÐÅÏ¢  
 | 
      
 | 
    playerID = curPlayer.GetPlayerID()  
 | 
      
 | 
    actInfo = PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_GrowupBuy, {})  
 | 
    actID = actInfo.get(ShareDefine.ActKey_ID, 0)  
 | 
    state = actInfo.get(ShareDefine.ActKey_State, 0)  
 | 
      
 | 
    playerActID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GrowupBuyID) # Íæ¼ÒÉíÉϵĻID  
 | 
      
 | 
    # »î¶¯ID ÏàͬµÄ»°²»´¦Àí  
 | 
    if actID == playerActID:  
 | 
        GameWorld.DebugLog("³É³¤±ØÂò»î¶¯ID²»±ä£¬²»´¦Àí£¡", curPlayer.GetPlayerID())  
 | 
        return  
 | 
    GameWorld.DebugLog("³É³¤±ØÂòÖØÖÃ! actID=%s,playerActID=%s,state=%s" % (actID, playerActID, state), playerID)  
 | 
      
 | 
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_GrowupBuyID, actID)  
 | 
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_GrowupBuyState, 0)  
 | 
      
 | 
    Sync_GrowupActionInfo(curPlayer)  
 | 
    return True  
 | 
  
 | 
def DoUpdateGrowupBuyStateOnDay(curPlayer):  
 | 
    ## ³É³¤±ØÂò¹ýÌì¸üйºÂò״̬  
 | 
      
 | 
    actInfo = PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_GrowupBuy, {})  
 | 
    if not actInfo:  
 | 
        return  
 | 
    if not actInfo.get(ShareDefine.ActKey_State):  
 | 
        return  
 | 
    cfgID = actInfo.get(ShareDefine.ActKey_CfgID)  
 | 
    ipyData = IpyGameDataPY.GetIpyGameData("ActGrowupBuy", cfgID)  
 | 
    if not ipyData:  
 | 
        return  
 | 
    ctgIDGroupList = ipyData.GetCTGIDGroupList()  
 | 
      
 | 
    buyState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GrowupBuyState)  
 | 
    GameWorld.DebugLog("¸üгɳ¤±ØÂò½ñÈտɹºÂòÀñ°üË÷Òý! buyState=%s,ctgIDGroupList=%s" % (buyState, ctgIDGroupList))  
 | 
      
 | 
    for i, ctgIDList in enumerate(ctgIDGroupList):  
 | 
          
 | 
        buyIndex = GameWorld.GetDataByDigitPlace(buyState, i)  
 | 
        updBuyIndex = 0  
 | 
        yestodayCtgID = ctgIDList[buyIndex]  
 | 
        if not curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TodayCTGCount % yestodayCtgID):  
 | 
            updBuyIndex = 0  
 | 
            GameWorld.DebugLog("    ×òÈÕÀñ°üûÂò£¬ÖØÖã¡yestodayCtgID=%s" % yestodayCtgID)  
 | 
        else:  
 | 
            if buyIndex >= len(ctgIDList) - 1:  
 | 
                updBuyIndex = len(ctgIDList) - 1  
 | 
                GameWorld.DebugLog("    ×òÈÕÀñ°üÒÑÂò£¬×îºóÒ»µµÀñ°ü±£³Ö²»±ä£¡ yestodayCtgID=%s,updBuyIndex=%s" % (yestodayCtgID, updBuyIndex))  
 | 
            else:  
 | 
                updBuyIndex = buyIndex + 1  
 | 
                GameWorld.DebugLog("    ×òÈÕÀñ°üÒÑÂò£¬¸üкóÐøÀñ°üË÷Òý£¡ yestodayCtgID=%s,updBuyIndex=%s" % (yestodayCtgID, updBuyIndex))  
 | 
                  
 | 
        buyState = GameWorld.ChangeDataByDigitPlace(buyState, i, updBuyIndex)  
 | 
        GameWorld.DebugLog("    updState=%s" % buyState)  
 | 
          
 | 
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_GrowupBuyState, buyState)  
 | 
    Sync_GrowupActionInfo(curPlayer)  
 | 
    return  
 | 
  
 | 
def CheckGrowupBuyState(curPlayer, ctgID):  
 | 
    ## ¼ì²éÊÇ·ñ¿É¹ºÂò³É³¤±ØÂòÀñ°üID  
 | 
    # @return: ÊÇ·ñ¿ÉÂò, ²»¿ÉÂòÔÒò˵Ã÷  
 | 
    actInfo = PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_GrowupBuy, {})  
 | 
    if not actInfo:  
 | 
        return False, "not grow up buy action info!"  
 | 
    if not actInfo.get(ShareDefine.ActKey_State):  
 | 
        return False, "grow up buy action state is 0!"  
 | 
    cfgID = actInfo.get(ShareDefine.ActKey_CfgID)  
 | 
    ipyData = IpyGameDataPY.GetIpyGameData("ActGrowupBuy", cfgID)  
 | 
    if not ipyData:  
 | 
        return False, "not grow up buy action ipyData cfgID(%s)!" % cfgID  
 | 
    ctgIDGroupList = ipyData.GetCTGIDGroupList()  
 | 
    buyState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GrowupBuyState)  
 | 
    curCTGIDList = []  
 | 
    playerBuyIndex = -1  
 | 
    for i, ctgIDList in enumerate(ctgIDGroupList):  
 | 
        if ctgID in ctgIDList:  
 | 
            curCTGIDList = ctgIDList  
 | 
            playerBuyIndex = GameWorld.GetDataByDigitPlace(buyState, i)  
 | 
            break  
 | 
    if not curCTGIDList:  
 | 
        return False, "ctgID(%s) is not in this grow up buy action ctgIDGroupList(%s)!" % (ctgID, ctgIDGroupList)  
 | 
    ctgIDIndex = curCTGIDList.index(ctgID)  
 | 
    if playerBuyIndex != ctgIDIndex:  
 | 
        return False, "ctgIDIndex(%s) is not equal to playerBuyIndex(%s) !" % (ctgIDIndex, playerBuyIndex)  
 | 
      
 | 
    return True, ""  
 | 
  
 | 
def Sync_GrowupActionInfo(curPlayer):  
 | 
    ## Í¨Öª»î¶¯ÐÅÏ¢  - ³É³¤±ØÂò  
 | 
    actInfo = PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_GrowupBuy, {})  
 | 
    if not actInfo:  
 | 
        return  
 | 
      
 | 
    if not actInfo.get(ShareDefine.ActKey_State):  
 | 
        return  
 | 
      
 | 
    cfgID = actInfo.get(ShareDefine.ActKey_CfgID)  
 | 
      
 | 
    ipyData = IpyGameDataPY.GetIpyGameData("ActGrowupBuy", cfgID)  
 | 
    if not ipyData:  
 | 
        return  
 | 
    ctgIDGroupList = ipyData.GetCTGIDGroupList()  
 | 
    if not ctgIDGroupList:  
 | 
        return  
 | 
      
 | 
    import PlayerCoin  
 | 
    buyState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GrowupBuyState)  
 | 
      
 | 
    openServerDay = GameWorld.GetGameWorld().GetGameWorldDictByKey(ShareDefine.Def_Notify_WorldKey_ServerDay) + 1  
 | 
    actPack = ChPyNetSendPack.tagMCActGrowupBuyInfo()  
 | 
    actPack.StartDate = GameWorld.GetOperationActionDateStr(ipyData.GetStartDate(), openServerDay)  
 | 
    actPack.EndtDate = GameWorld.GetOperationActionDateStr(ipyData.GetEndDate(), openServerDay)  
 | 
    actPack.LimitLV = ipyData.GetLVLimit()  
 | 
    actPack.GroupList = []  
 | 
    for i, ctgIDList in enumerate(ctgIDGroupList):  
 | 
        groupInfo = ChPyNetSendPack.tagMCActGrowupBuyGroup()  
 | 
        groupInfo.BuyCTGIDList = []  
 | 
        for ctgID in ctgIDList:  
 | 
            ctgIpyData = IpyGameDataPY.GetIpyGameData("CTG", ctgID)  
 | 
            ctgGiveItemList = PlayerCoin.GetCTGGiveItemList(ctgIpyData)  
 | 
            ctgInfo = ChPyNetSendPack.tagMCActGrowupBuyCTGInfo()  
 | 
            ctgInfo.CTGID = ctgID  
 | 
            ctgInfo.GainItemList = []  
 | 
            for itemID, itemCount, isAuctionItem in ctgGiveItemList:  
 | 
                ctgItem = ChPyNetSendPack.tagMCActGrowupBuyCTGItem()  
 | 
                ctgItem.ItemID = itemID  
 | 
                ctgItem.ItemCount = itemCount  
 | 
                ctgItem.IsBind = isAuctionItem  
 | 
                ctgInfo.GainItemList.append(ctgItem)  
 | 
            ctgInfo.GainItemCount = len(ctgInfo.GainItemList)  
 | 
            groupInfo.BuyCTGIDList.append(ctgInfo)  
 | 
        groupInfo.BuyCount = len(groupInfo.BuyCTGIDList)  
 | 
        groupInfo.PlayerBuyIndex = GameWorld.GetDataByDigitPlace(buyState, i)  
 | 
        actPack.GroupList.append(groupInfo)  
 | 
    actPack.GroupCount = len(actPack.GroupList)  
 | 
    NetPackCommon.SendFakePack(curPlayer, actPack)  
 | 
    return  
 |