| #!/usr/bin/python  | 
| # -*- coding: GBK -*-  | 
| #-------------------------------------------------------------------------------  | 
| #  | 
| ##@package Player.PlayerActRechargePrize  | 
| #  | 
| # @todo:³äÖµ·µÀû»î¶¯  | 
| # @author hxp  | 
| # @date 2020-09-23  | 
| # @version 1.0  | 
| #  | 
| # ÏêϸÃèÊö: ³äÖµ·µÀû»î¶¯  | 
| #  | 
| #-------------------------------------------------------------------------------  | 
| #"""Version = 2020-09-23 12:00"""  | 
| #-------------------------------------------------------------------------------  | 
|   | 
| import PyGameData  | 
| import ShareDefine  | 
| import PlayerControl  | 
| import IpyGameDataPY  | 
| import ChPyNetSendPack  | 
| import NetPackCommon  | 
| import GameWorld  | 
| import ChConfig  | 
|   | 
| def __GetActTemplateID(cfgID, dayIndex):  | 
|     if cfgID == None or dayIndex == None:  | 
|         return 0  | 
|     ipyData = IpyGameDataPY.GetIpyGameData("ActRechargePrize", cfgID)  | 
|     if not ipyData:  | 
|         return 0  | 
|     templateIDList = ipyData.GetTemplateIDList()  | 
|     templateID = templateIDList[-1] if dayIndex >= len(templateIDList) else templateIDList[dayIndex]  | 
|     return templateID  | 
|   | 
| def OnPlayerLogin(curPlayer):  | 
|     isReset = __CheckPlayerRechargePrizeAction(curPlayer)  | 
|     if not isReset:  | 
|         actInfo = PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_RechargePrize, {})  | 
|         # »î¶¯ÖÐͬ²½»î¶¯ÐÅÏ¢  | 
|         if actInfo.get(ShareDefine.ActKey_State):  | 
|             Sync_RechargePrizeActionInfo(curPlayer)  | 
|             Sync_RechargePrizeInfo(curPlayer)  | 
|     return  | 
|   | 
| def RefreshRechargePrizeActionInfo():  | 
|     ## ÊÕµ½GameServerͬ²½µÄ»î¶¯ÐÅÏ¢£¬Ë¢Ð»ÐÅÏ¢  | 
|     playerManager = GameWorld.GetPlayerManager()  | 
|     for index in xrange(playerManager.GetPlayerCount()):  | 
|         curPlayer = playerManager.GetPlayerByIndex(index)  | 
|         if curPlayer.GetID() == 0:  | 
|             continue  | 
|         __CheckPlayerRechargePrizeAction(curPlayer)  | 
|     return  | 
|   | 
| def __CheckPlayerRechargePrizeAction(curPlayer):  | 
|     ## ¼ì²éÍæ¼Ò³äÖµ·µÀû»î¶¯Êý¾ÝÐÅÏ¢  | 
|       | 
|     playerID = curPlayer.GetPlayerID()  | 
|       | 
|     actInfo = PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_RechargePrize, {})  | 
|     actID = actInfo.get(ShareDefine.ActKey_ID, 0)  | 
|     state = actInfo.get(ShareDefine.ActKey_State, 0)  | 
|       | 
|     playerActID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_RechargePrizeID) # Íæ¼ÒÉíÉϵĻID  | 
|       | 
|     # »î¶¯ID ÏàͬµÄ»°²»´¦Àí  | 
|     if actID == playerActID:  | 
|         GameWorld.DebugLog("³äÖµ·µÀû»î¶¯ID²»±ä£¬²»´¦Àí£¡", curPlayer.GetPlayerID())  | 
|         return  | 
|     GameWorld.DebugLog("³äÖµ·µÀûÖØÖÃ! actID=%s,playerActID=%s,state=%s" % (actID, playerActID, state), playerID)  | 
|       | 
|     templateID = __GetActTemplateID(actInfo.get(ShareDefine.ActKey_CfgID, 0), actInfo.get(ShareDefine.ActKey_DayIndex, 0))  | 
|       | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_RechargePrizeID, actID)  | 
|       | 
|     ipyDataList = IpyGameDataPY.GetIpyGameDataList("RechargePrizeTemplate", templateID)  | 
|     if ipyDataList:  | 
|         for ipyData in ipyDataList:  | 
|             PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_RechargePrizeCount % ipyData.GetCTGID(), 0)  | 
|               | 
|     Sync_RechargePrizeActionInfo(curPlayer)  | 
|     Sync_RechargePrizeInfo(curPlayer)  | 
|     return True  | 
|   | 
| def DoAddPlayerActRechargePrizeCount(curPlayer, ctgID):  | 
|     ## Ö´ÐÐÔö¼ÓÍæ¼Ò³äÖµ·µÀû»î¶¯·µÀû´ÎÊý  | 
|     # @return: ·µÀûÏÉÓñ Êý  | 
|     actInfo = PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_RechargePrize, {})  | 
|     if not actInfo:  | 
|         GameWorld.DebugLog("ÎÞ³äÖµ·µÀû»î¶¯")  | 
|         return  | 
|     if not actInfo.get(ShareDefine.ActKey_State):  | 
|         GameWorld.DebugLog("³äÖµ·µÀû»î¶¯Î´¿ªÆô")  | 
|         return  | 
|     templateID = __GetActTemplateID(actInfo.get(ShareDefine.ActKey_CfgID, 0), actInfo.get(ShareDefine.ActKey_DayIndex, 0))  | 
|     actIpyData = None  | 
|     ipyDataList = IpyGameDataPY.GetIpyGameDataList("RechargePrizeTemplate", templateID)  | 
|     if ipyDataList:  | 
|         for ipyData in ipyDataList:  | 
|             if ctgID == ipyData.GetCTGID():  | 
|                 actIpyData = ipyData  | 
|                 break  | 
|     if not actIpyData:  | 
|         GameWorld.DebugLog("¸Ã³äÖµIDÎÞ³äÖµ·µÀû! ctgID=%s,templateID=%s" % (ctgID, templateID))  | 
|         return  | 
|       | 
|     prizeCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_RechargePrizeCount % ctgID)  | 
|     prizeCountLimit = actIpyData.GetPrizeCountLimit()  | 
|     if prizeCount >= prizeCountLimit:  | 
|         GameWorld.DebugLog("ÒÑ´ï³äÖµ·µÀû×î´ó´ÎÊý: ctgID=%s,prizeCount=%s" % (ctgID, prizeCount))  | 
|         return  | 
|     prizeCount += 1  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_RechargePrizeCount % ctgID, prizeCount)  | 
|     goldPrize = actIpyData.GetGoldPrize()  | 
|       | 
|     Sync_RechargePrizeInfo(curPlayer, ctgID)  | 
|     GameWorld.DebugLog("³äÖµ·µÀû: ctgID=%s,goldPrize=%s,prizeCount=%s" % (ctgID, goldPrize, prizeCount))  | 
|     return goldPrize  | 
|   | 
| def Sync_RechargePrizeInfo(curPlayer, ctgID=0):  | 
|     ## Í¨Öª³äÖµ·µÀûÍæ¼ÒÊý¾ÝÐÅÏ¢  | 
|     actInfo = PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_RechargePrize, {})  | 
|     if not actInfo:  | 
|         return  | 
|     if not actInfo.get(ShareDefine.ActKey_State):  | 
|         return  | 
|     templateID = __GetActTemplateID(actInfo.get(ShareDefine.ActKey_CfgID, 0), actInfo.get(ShareDefine.ActKey_DayIndex, 0))  | 
|       | 
|     if ctgID > 0:  | 
|         syncCTGIDList = [ctgID]  | 
|     else:  | 
|         syncCTGIDList = []  | 
|         ipyDataList = IpyGameDataPY.GetIpyGameDataList("RechargePrizeTemplate", templateID)  | 
|         if ipyDataList:  | 
|             for ipyData in ipyDataList:  | 
|                 syncCTGIDList.append(ipyData.GetCTGID())  | 
|                   | 
|     playerActInfo = ChPyNetSendPack.tagMCRechargePrizePlayerInfo()  | 
|     playerActInfo.PlayerInfoList = []  | 
|     for syncCTGID in syncCTGIDList:  | 
|         prizeInfo = ChPyNetSendPack.tagMCRechargePrizeInfo()  | 
|         prizeInfo.CTGID = syncCTGID  | 
|         prizeInfo.PrizeCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_RechargePrizeCount % syncCTGID)  | 
|         playerActInfo.PlayerInfoList.append(prizeInfo)  | 
|     playerActInfo.Count = len(playerActInfo.PlayerInfoList)  | 
|     NetPackCommon.SendFakePack(curPlayer, playerActInfo)  | 
|     return  | 
|   | 
| def Sync_RechargePrizeActionInfo(curPlayer):  | 
|     ## Í¨Öª³äÖµ·µÀû»î¶¯ÐÅÏ¢  | 
|     actInfo = PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_RechargePrize, {})  | 
|     if not actInfo:  | 
|         return  | 
|       | 
|     if not actInfo.get(ShareDefine.ActKey_State):  | 
|         return  | 
|       | 
|     cfgID = actInfo.get(ShareDefine.ActKey_CfgID)  | 
|     ipyData = IpyGameDataPY.GetIpyGameData("ActRechargePrize", cfgID)  | 
|     if not ipyData:  | 
|         return  | 
|       | 
|     templateIDList = ipyData.GetTemplateIDList()  | 
|     if not templateIDList:  | 
|         return  | 
|     startDateStr, endDateStr = GameWorld.GetOperationActionDateStr(ipyData)  | 
|     actInfo = ChPyNetSendPack.tagMCActRechargePrizeInfo()  | 
|     actInfo.StartDate = startDateStr  | 
|     actInfo.EndtDate = endDateStr  | 
|     actInfo.LimitLV = ipyData.GetLVLimit()  | 
|     actInfo.IsDayReset = ipyData.GetIsDayReset()  | 
|     actInfo.PrizeDayInfo = []  | 
|     for templateID in templateIDList:  | 
|         ipyDataList = IpyGameDataPY.GetIpyGameDataList("RechargePrizeTemplate", templateID)  | 
|         if not ipyDataList:  | 
|             continue  | 
|           | 
|         dayInfo = ChPyNetSendPack.tagMCActRechargePrizeDay()  | 
|         dayInfo.PrizeInfo = []  | 
|         for prizeData in ipyDataList:  | 
|             prize = ChPyNetSendPack.tagMCActRechargePrize()  | 
|             prize.CTGID = prizeData.GetCTGID()  | 
|             prize.GoldPrize = prizeData.GetGoldPrize()  | 
|             prize.PrizeCountLimit = prizeData.GetPrizeCountLimit()  | 
|             dayInfo.PrizeInfo.append(prize)  | 
|               | 
|         dayInfo.Prizes = len(dayInfo.PrizeInfo)  | 
|         actInfo.PrizeDayInfo.append(dayInfo)  | 
|           | 
|     actInfo.PrizeDays = len(actInfo.PrizeDayInfo)  | 
|     NetPackCommon.SendFakePack(curPlayer, actInfo)  | 
|     return  | 
|   | 
|   |