| #!/usr/bin/python  | 
| # -*- coding: GBK -*-  | 
| #-------------------------------------------------------------------------------  | 
| #  | 
| ##@package Player.PlayerActTotalRecharge  | 
| #  | 
| # @todo:ÀۼƳäÖµ»î¶¯  | 
| # @author hxp  | 
| # @date 2018-7-16  | 
| # @version 1.0  | 
| #  | 
| # ÏêϸÃèÊö: ÀۼƳäÖµ»î¶¯  | 
| #  | 
| #-------------------------------------------------------------------------------  | 
| #"""Version = 2018-7-16 12:00"""  | 
| #-------------------------------------------------------------------------------  | 
|   | 
| import PyGameData  | 
| import ShareDefine  | 
| import PlayerControl  | 
| import IpyGameDataPY  | 
| import ItemControler  | 
| import ChPyNetSendPack  | 
| import DataRecordPack  | 
| import IPY_GameWorld  | 
| import NetPackCommon  | 
| import ItemCommon  | 
| import GameWorld  | 
| import ChConfig  | 
|   | 
| def GetTemplateID(cfgID, dayIndex):  | 
|     if cfgID == None or dayIndex == None:  | 
|         return 0  | 
|     ipyData = IpyGameDataPY.GetIpyGameData("ActTotalRecharge", 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 = __CheckPlayerTotalRechargeAction(curPlayer)  | 
|     if not isReset:  | 
|         actTotalRechargeInfo = PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_TotalRecharge, {})  | 
|         # »î¶¯ÖÐͬ²½»î¶¯ÐÅÏ¢  | 
|         if actTotalRechargeInfo.get(ShareDefine.ActKey_State):  | 
|             Sync_TotalRechargeActionInfo(curPlayer)  | 
|             Sync_TotalRechargeInfo(curPlayer)  | 
|     return  | 
|   | 
| def RefreshTotalRechargeActionInfo():  | 
|     ## ÊÕµ½GameServerͬ²½µÄ»î¶¯ÐÅÏ¢£¬Ë¢Ð»ÐÅÏ¢  | 
|     playerManager = GameWorld.GetPlayerManager()  | 
|     for index in xrange(playerManager.GetPlayerCount()):  | 
|         curPlayer = playerManager.GetPlayerByIndex(index)  | 
|         if curPlayer.GetID() == 0:  | 
|             continue  | 
|         __CheckPlayerTotalRechargeAction(curPlayer)  | 
|     return  | 
|   | 
| def __CheckPlayerTotalRechargeAction(curPlayer):  | 
|     ## ¼ì²éÍæ¼ÒÀۼƳäÖµ»î¶¯Êý¾ÝÐÅÏ¢  | 
|       | 
|     playerID = curPlayer.GetPlayerID()  | 
|       | 
|     actTotalRechargeInfo = PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_TotalRecharge, {})  | 
|     TotalRechargeID = actTotalRechargeInfo.get(ShareDefine.ActKey_ID, 0)  | 
|     state = actTotalRechargeInfo.get(ShareDefine.ActKey_State, 0)  | 
|       | 
|     playerTotalRechargeID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TotalRechargeID) # Íæ¼ÒÉíÉϵĻID  | 
|       | 
|     # »î¶¯ID ÏàͬµÄ»°²»´¦Àí  | 
|     if TotalRechargeID == playerTotalRechargeID:  | 
|         #GameWorld.DebugLog("ÀۼƳäÖµ»î¶¯ID²»±ä£¬²»´¦Àí£¡", curPlayer.GetPlayerID())  | 
|         return  | 
|       | 
|     templateID = GetTemplateID(actTotalRechargeInfo.get(ShareDefine.ActKey_CfgID, 0), actTotalRechargeInfo.get(ShareDefine.ActKey_DayIndex, 0))  | 
|     playerTemplateID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TotalRechargeTemplateID)  | 
|       | 
|     GameWorld.DebugLog("ÀۼƳäÖµÖØÖÃ! TotalRechargeID=%s,playerTotalRechargeID=%s,state=%s,templateID=%s,playerTemplateID=%s"   | 
|                        % (TotalRechargeID, playerTotalRechargeID, state, templateID, playerTemplateID), playerID)  | 
|       | 
|     # Î´ÁìÈ¡µÄ½±ÀøÓʼþ·¢·Å  | 
|     __SendTotalRechargeMail(curPlayer, playerTemplateID)  | 
|       | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TotalRechargeID, TotalRechargeID)  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TotalRechargeTemplateID, templateID)  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TotalRechargeGold, 0)  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TotalRechargeAwardRecord, 0)  | 
|       | 
|     Sync_TotalRechargeActionInfo(curPlayer)  | 
|     Sync_TotalRechargeInfo(curPlayer)  | 
|     return True  | 
|   | 
| def __SendTotalRechargeMail(curPlayer, playerTemplateID):  | 
|     # Î´ÁìÈ¡µÄ½±ÀøÓʼþ·¢·Å  | 
|       | 
|     if not playerTemplateID:  | 
|         return  | 
|       | 
|     curRechargeGold = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TotalRechargeGold)  | 
|     if not curRechargeGold:  | 
|         return  | 
|       | 
|     ipyDataList = IpyGameDataPY.GetIpyGameDataList("TotalRechargeTemplate", playerTemplateID)  | 
|     if not ipyDataList:  | 
|         return  | 
|       | 
|     playerID = curPlayer.GetPlayerID()  | 
|     batchPlayerIDList, batchAddItemList, batchParamList = [], [], []  | 
|     awardRecord = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TotalRechargeAwardRecord)  | 
|     job = curPlayer.GetJob()  | 
|     for ipyData in ipyDataList:  | 
|         awardIndex = ipyData.GetAwardIndex()  | 
|         if awardRecord & pow(2, awardIndex):  | 
|             continue  | 
|           | 
|         needGold = ipyData.GetNeedGold()  | 
|         if curRechargeGold < needGold:  | 
|             continue  | 
|         awardRecord |= pow(2, awardIndex)   | 
|           | 
|         awardItemList = ipyData.GetAwardItem().get(str(job), [])  | 
|         batchPlayerIDList.append([playerID])  | 
|         batchAddItemList.append(awardItemList)  | 
|         batchParamList.append([needGold])  | 
|           | 
|     if batchPlayerIDList:  | 
|         PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TotalRechargeAwardRecord, awardRecord)  | 
|         PlayerControl.SendMailBatch("TotalRechargeMail", batchPlayerIDList, batchAddItemList, batchParamList)  | 
|           | 
|     return  | 
|   | 
| def AddTotalRechargeGold(curPlayer, addGold):  | 
|     if addGold <= 0:  | 
|         return  | 
|      | 
|       | 
|     actTotalRechargeInfo = PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_TotalRecharge, {})  | 
|     if not actTotalRechargeInfo.get(ShareDefine.ActKey_State):  | 
|         GameWorld.DebugLog("ÀۼƳäÖµ»î¶¯µ±Ç°Î´¿ªÆô!")  | 
|         return  | 
|       | 
|     actID = actTotalRechargeInfo.get(ShareDefine.ActKey_ID)  | 
|     templateID = GetTemplateID(actTotalRechargeInfo.get(ShareDefine.ActKey_CfgID, 0), actTotalRechargeInfo.get(ShareDefine.ActKey_DayIndex, 0))  | 
|     if not actID or not templateID:  | 
|         GameWorld.ErrLog("ÀۼƳäÖµ»î¶¯Êý¾ÝÒì³£!actID=%s,templateID=%s" % (actID, templateID), curPlayer.GetPlayerID())  | 
|         return  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TotalRechargeID, actID)  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TotalRechargeTemplateID, templateID)  | 
|       | 
|     curRechargeGold = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TotalRechargeGold)  | 
|     updRechargeGold = curRechargeGold + addGold  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TotalRechargeGold, updRechargeGold)  | 
|     Sync_TotalRechargeInfo(curPlayer)  | 
|     GameWorld.DebugLog("Íæ¼ÒÀۼƳäÖµ»î¶¯: actID=%s,templateID=%s,curRechargeGold=%s,addGold=%s,updRechargeGold=%s"   | 
|                        % (actID, templateID, curRechargeGold, addGold, updRechargeGold), curPlayer.GetPlayerID())  | 
|     return  | 
|   | 
| def OnGetTotalRechargeAward(curPlayer, awardIndex):  | 
|     ## ÁìÈ¡ÀۼƳäÖµ½±Àø  | 
|   | 
|     playerID = curPlayer.GetPlayerID()  | 
|       | 
|     actTotalRechargeInfo = PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_TotalRecharge, {})  | 
|     TotalRechargeID = actTotalRechargeInfo.get(ShareDefine.ActKey_ID, 0)  | 
|     state = actTotalRechargeInfo.get(ShareDefine.ActKey_State, 0)  | 
|     templateID = GetTemplateID(actTotalRechargeInfo.get(ShareDefine.ActKey_CfgID, 0), actTotalRechargeInfo.get(ShareDefine.ActKey_DayIndex, 0))  | 
|     if not state or not templateID:  | 
|         GameWorld.DebugLog("ûÓÐÀۼƳäÖµ»î¶¯£¬ÎÞ·¨Áì½±£¡state=%s,templateID=%s" % (state, templateID), playerID)  | 
|         return  | 
|       | 
|     playerTotalRechargeID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TotalRechargeID) # Íæ¼ÒÉíÉϵĻID  | 
|     if TotalRechargeID != playerTotalRechargeID:  | 
|         return  | 
|       | 
|     awardRecord = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TotalRechargeAwardRecord)  | 
|     if awardRecord & pow(2, awardIndex):  | 
|         GameWorld.DebugLog("ÒѾÁìÈ¡¹ý¸ÃÀۼƳäÖµ»î¶¯½±Àø!awardIndex=%s" % awardIndex, playerID)  | 
|         return  | 
|       | 
|     ipyDataList = IpyGameDataPY.GetIpyGameDataList("TotalRechargeTemplate", templateID)  | 
|     if not ipyDataList:  | 
|         return  | 
|       | 
|     awardIpyData = None  | 
|     for ipyData in ipyDataList:  | 
|         if ipyData.GetAwardIndex() == awardIndex:  | 
|             awardIpyData = ipyData  | 
|             break  | 
|           | 
|     if not awardIpyData:  | 
|         GameWorld.DebugLog("ÕÒ²»µ½¸Ã·µÀû»î¶¯µµÎ»Ë÷Òý½±Àø!templateID=%s,awardIndex=%s" % (templateID, awardIndex), playerID)  | 
|         return  | 
|       | 
|     needGold = awardIpyData.GetNeedGold()  | 
|     awardItemList = awardIpyData.GetAwardItem().get(str(curPlayer.GetJob()), [])  | 
|       | 
|     curRechargeGold = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TotalRechargeGold)  | 
|     if curRechargeGold < needGold:  | 
|         GameWorld.DebugLog("ËùÐè³äÖµÏÉÓñÊý²»×㣬ÎÞ·¨ÁìÈ¡!templateID=%s,awardIndex=%s,needGold=%s,curRechargeGold=%s"   | 
|                            % (templateID, awardIndex, needGold, curRechargeGold), playerID)  | 
|         return  | 
|       | 
|     needSpace = len(awardItemList)  | 
|     packSpace = ItemCommon.GetItemPackSpace(curPlayer, IPY_GameWorld.rptItem, needSpace)  | 
|     if packSpace < needSpace:  | 
|         return  | 
|       | 
|     awardRecord |= pow(2, awardIndex)  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TotalRechargeAwardRecord, awardRecord)  | 
|     Sync_TotalRechargeInfo(curPlayer)  | 
|       | 
|     notifyKey = awardIpyData.GetNotifyKey()  | 
|     if notifyKey:  | 
|         PlayerControl.WorldNotify(0, notifyKey, [curPlayer.GetPlayerName(), needGold])  | 
|           | 
|     for itemID, itemCount, isBind in awardItemList:  | 
|         ItemControler.GivePlayerItem(curPlayer, itemID, itemCount, isBind, [IPY_GameWorld.rptItem])  | 
|           | 
|     addDataDict = {"TemplateID":templateID, "NeedGold":needGold, "AwardIndex":awardIndex,  | 
|                    "ItemList":str(awardItemList)}  | 
|     DataRecordPack.DR_FuncGiveItem(curPlayer, "TotalRechargeAward", addDataDict)  | 
|     return  | 
|   | 
| def Sync_TotalRechargeInfo(curPlayer):  | 
|     ## Í¨ÖªÀۼƳäÖµÍæ¼ÒÊý¾ÝÐÅÏ¢  | 
|     playerActInfo = ChPyNetSendPack.tagMCTotalRechargePlayerInfo()  | 
|     playerActInfo.GoldTotal = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TotalRechargeGold)  | 
|     playerActInfo.AwardRecord = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TotalRechargeAwardRecord)  | 
|     NetPackCommon.SendFakePack(curPlayer, playerActInfo)  | 
|     return  | 
|   | 
| def Sync_TotalRechargeActionInfo(curPlayer):  | 
|     ## Í¨ÖªÀۼƳäÖµ»î¶¯ÐÅÏ¢  | 
|     actTotalRechargeInfo = PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_TotalRecharge, {})  | 
|     if not actTotalRechargeInfo:  | 
|         return  | 
|       | 
|     if not actTotalRechargeInfo.get(ShareDefine.ActKey_State):  | 
|         return  | 
|       | 
|     cfgID = actTotalRechargeInfo.get(ShareDefine.ActKey_CfgID)  | 
|     ipyData = IpyGameDataPY.GetIpyGameData("ActTotalRecharge", cfgID)  | 
|     if not ipyData:  | 
|         return  | 
|       | 
|     templateIDList = ipyData.GetTemplateIDList()  | 
|     if not templateIDList:  | 
|         return  | 
|     job = curPlayer.GetJob()  | 
|     openServerDay = GameWorld.GetGameWorld().GetGameWorldDictByKey(ShareDefine.Def_Notify_WorldKey_ServerDay) + 1  | 
|     actInfo = ChPyNetSendPack.tagMCActTotalRechargeInfo()  | 
|     actInfo.StartDate = GameWorld.GetOperationActionDateStr(ipyData.GetStartDate(), openServerDay)  | 
|     actInfo.EndtDate = GameWorld.GetOperationActionDateStr(ipyData.GetEndDate(), openServerDay)  | 
|     actInfo.LimitLV = ipyData.GetLVLimit()  | 
|     actInfo.IsDayReset = ipyData.GetIsDayReset()  | 
|     actInfo.AwardDayInfo = []  | 
|     for templateID in templateIDList:  | 
|         ipyDataList = IpyGameDataPY.GetIpyGameDataList("TotalRechargeTemplate", templateID)  | 
|         if not ipyDataList:  | 
|             continue  | 
|           | 
|         dayInfo = ChPyNetSendPack.tagMCTotalRechargeAwardDay()  | 
|         dayInfo.AwardInfo = []  | 
|         for ipyData in ipyDataList:  | 
|             awardInfo = ChPyNetSendPack.tagMCTotalRechargeAward()  | 
|             awardInfo.AwardIndex = ipyData.GetAwardIndex()  | 
|             awardInfo.NeedGold = ipyData.GetNeedGold()  | 
|             awardInfo.AwardItem = []  | 
|             awardItemDict = ipyData.GetAwardItem()  | 
|             for itemID, itemCount, isBind in awardItemDict.get(str(job), []):  | 
|                 awardItem = ChPyNetSendPack.tagMCTotalRechargeAwardItem()  | 
|                 awardItem.ItemID = itemID  | 
|                 awardItem.ItemCount = itemCount  | 
|                 awardItem.IsBind = isBind  | 
|                 awardInfo.AwardItem.append(awardItem)  | 
|             awardInfo.AwardItemCount = len(awardInfo.AwardItem)  | 
|               | 
|             dayInfo.AwardInfo.append(awardInfo)  | 
|               | 
|         dayInfo.AwardCount = len(dayInfo.AwardInfo)  | 
|         actInfo.AwardDayInfo.append(dayInfo)  | 
|           | 
|     actInfo.AwardDays = len(actInfo.AwardDayInfo)  | 
|     NetPackCommon.SendFakePack(curPlayer, actInfo)  | 
|     return  | 
|   | 
|   |