| #!/usr/bin/python  | 
| # -*- coding: GBK -*-  | 
| #-------------------------------------------------------------------------------  | 
| #  | 
| ##@package Player.PlayerActManyDayRecharge  | 
| #  | 
| # @todo:¶àÈÕÁ¬³ä  | 
| # @author hxp  | 
| # @date 2021-03-12  | 
| # @version 1.0  | 
| #  | 
| # ÏêϸÃèÊö: ¶àÈÕÁ¬³ä  | 
| #  | 
| #-------------------------------------------------------------------------------  | 
| #"""Version = 2021-03-12 15:00"""  | 
| #-------------------------------------------------------------------------------  | 
|   | 
| import PyGameData  | 
| import ShareDefine  | 
| import PlayerControl  | 
| import IpyGameDataPY  | 
| import ItemControler  | 
| import ChPyNetSendPack  | 
| import DataRecordPack  | 
| import IPY_GameWorld  | 
| import NetPackCommon  | 
| import GameWorld  | 
| import ChConfig  | 
| import CommFunc  | 
|   | 
| Max_ActDays = 7 # Ö§³Ö×î´ó»î¶¯³ÖÐøÌì  | 
|   | 
| def GetTemplateID(cfgID):  | 
|     if not cfgID:  | 
|         return 0  | 
|     ipyData = IpyGameDataPY.GetIpyGameData("ActManyDayRecharge", cfgID)  | 
|     if not ipyData:  | 
|         return 0  | 
|     return ipyData.GetTemplateID()  | 
|   | 
| def OnPlayerLogin(curPlayer):  | 
|       | 
|     for actInfo in PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_ManyDayRecharge, {}).values():  | 
|         actNum = actInfo.get(ShareDefine.ActKey_ActNum, 0)  | 
|         isReset = __CheckPlayerManyDayRechargeAction(curPlayer, actNum)  | 
|         if not isReset:  | 
|             # »î¶¯ÖÐͬ²½»î¶¯ÐÅÏ¢  | 
|             if actInfo.get(ShareDefine.ActKey_State):  | 
|                 Sync_ManyDayRechargeActionInfo(curPlayer, actNum)  | 
|                 Sync_ManyDayRechargePlayerInfo(curPlayer, actNum)  | 
|                   | 
|     return  | 
|   | 
| def RefreshManyDayRechargeActionInfo(actNum):  | 
|     ## ÊÕµ½GameServerͬ²½µÄ»î¶¯ÐÅÏ¢£¬Ë¢Ð»ÐÅÏ¢  | 
|     playerManager = GameWorld.GetPlayerManager()  | 
|     for index in xrange(playerManager.GetPlayerCount()):  | 
|         curPlayer = playerManager.GetPlayerByIndex(index)  | 
|         if curPlayer.GetID() == 0:  | 
|             continue  | 
|         __CheckPlayerManyDayRechargeAction(curPlayer, actNum)  | 
|     return  | 
|   | 
| def __CheckPlayerManyDayRechargeAction(curPlayer, actNum):  | 
|     ## ¼ì²éÍæ¼Ò»î¶¯Êý¾ÝÐÅÏ¢  | 
|       | 
|     playerID = curPlayer.GetPlayerID()  | 
|     actInfo = GameWorld.GetActInfo(ShareDefine.OperationActionName_ManyDayRecharge, actNum)  | 
|     actID = actInfo.get(ShareDefine.ActKey_ID, 0)  | 
|     state = actInfo.get(ShareDefine.ActKey_State, 0)  | 
|     templateID = GetTemplateID(actInfo.get(ShareDefine.ActKey_CfgID, 0))  | 
|       | 
|     playerActID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ManyDayRechargeID % actNum) # Íæ¼ÒÉíÉϵĻID  | 
|     playerTemplateID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ManyDayRechargeTempID % actNum)  | 
|       | 
|     # »î¶¯ID ÏàͬµÄ»°²»´¦Àí  | 
|     if actID == playerActID:  | 
|         GameWorld.DebugLog("¶àÈÕÁ¬³ä»î¶¯ID²»±ä£¬²»´¦Àí£¡actNum=%s,actID=%s" % (actNum, actID), playerID)  | 
|         if state and templateID and templateID != playerTemplateID:  | 
|             PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ManyDayRechargeTempID % actNum, templateID)  | 
|             Sync_ManyDayRechargePlayerInfo(curPlayer, actNum)  | 
|             GameWorld.DebugLog("    »î¶¯ÖиüÐÂÄ£°åID: templateID=%s" % templateID, playerID)  | 
|               | 
|         return  | 
|       | 
|     actWorldLV = actInfo.get(ShareDefine.ActKey_WorldLV, 0)  | 
|     playerWorldLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ManyDayRechargeWorldLV % actNum)  | 
|       | 
|     GameWorld.DebugLog("¶àÈÕÁ¬³äÖØÖÃ! actNum=%s,actID=%s,playerActID=%s,state=%s,templateID=%s,playerTemplateID=%s"   | 
|                        % (actNum, actID, playerActID, state, templateID, playerTemplateID), playerID)  | 
|       | 
|     # Î´ÁìÈ¡µÄ½±ÀøÓʼþ·¢·Å  | 
|     __SendManyDayRechargeMail(curPlayer, playerTemplateID, playerWorldLV, actNum)  | 
|       | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ManyDayRechargeID % actNum, actID)  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ManyDayRechargeTempID % actNum, templateID)  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ManyDayRechargeWorldLV % actNum, actWorldLV)  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ManyDayRechargeAward % actNum, 0)  | 
|     for dayIndex in xrange(Max_ActDays):  | 
|         PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ManyDayRechargeValue % (actNum, dayIndex), 0)  | 
|           | 
|     Sync_ManyDayRechargeActionInfo(curPlayer, actNum)  | 
|     Sync_ManyDayRechargePlayerInfo(curPlayer, actNum)  | 
|     return True  | 
|   | 
| def __SendManyDayRechargeMail(curPlayer, playerTemplateID, playerWorldLV, actNum):  | 
|     # Î´ÁìÈ¡µÄ½±ÀøÓʼþ·¢·Å  | 
|       | 
|     if not playerTemplateID:  | 
|         return  | 
|       | 
|     ipyDataList = IpyGameDataPY.GetIpyGameDataList("ActManyDayRechargeAward", playerTemplateID)  | 
|     if not ipyDataList:  | 
|         return  | 
|       | 
|     playerID = curPlayer.GetPlayerID()  | 
|     batchPlayerIDList, batchAddItemList, batchParamList = [], [], []  | 
|     awardRecord = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ManyDayRechargeAward % actNum)  | 
|       | 
|     for ipyData in ipyDataList:  | 
|         awardIndex = ipyData.GetAwardIndex()  | 
|         if awardRecord & pow(2, awardIndex):  | 
|             continue  | 
|           | 
|         needRechargeValue = CommFunc.RMBToCoin(ipyData.GetNeedRMB())  | 
|         needDays = ipyData.GetNeedDays()  | 
|         finishDays = 0  | 
|         for dayIndex in xrange(Max_ActDays):  | 
|             rechargeValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ManyDayRechargeValue % (actNum, dayIndex))  | 
|             if rechargeValue >= needRechargeValue:  | 
|                 finishDays += 1  | 
|                   | 
|         if finishDays < needDays:  | 
|             continue  | 
|           | 
|         awardRecord |= pow(2, awardIndex)   | 
|         awardItemList = GameWorld.GetDictValueByRangeKey(ipyData.GetAwardItemInfo(), playerWorldLV, [])  | 
|           | 
|         batchPlayerIDList.append([playerID])  | 
|         batchAddItemList.append(awardItemList)  | 
|         batchParamList.append([needDays, str(ipyData.GetNeedRMB())])  | 
|         GameWorld.Log("¶àÈÕÁ¬³ä»î¶¯²¹·¢½±Àø! actNum=%s,playerTemplateID=%s,awardIndex=%s" % (actNum, playerTemplateID, awardIndex))  | 
|           | 
|     if batchPlayerIDList:  | 
|         PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ManyDayRechargeAward % actNum, awardRecord)  | 
|         actType = actNum / 10  | 
|         PlayerControl.SendMailBatch("ManyDayRechargeMail%s" % actType, batchPlayerIDList, batchAddItemList, batchParamList)  | 
|           | 
|     return  | 
|   | 
| def AddManyDayRechargeValue(curPlayer, addValue):  | 
|     if addValue <= 0:  | 
|         return  | 
|       | 
|     for actInfo in PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_ManyDayRecharge, {}).values():  | 
|         actNum = actInfo.get(ShareDefine.ActKey_ActNum, 0)  | 
|         dayIndex = actInfo.get(ShareDefine.ActKey_DayIndex, 0)  | 
|         if not actInfo.get(ShareDefine.ActKey_State):  | 
|             GameWorld.DebugLog("¶àÈÕÁ¬³ä»î¶¯µ±Ç°Î´¿ªÆô! actNum=%s" % actNum)  | 
|             continue  | 
|           | 
|         curRechargeValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ManyDayRechargeValue % (actNum, dayIndex))  | 
|         updRechargeValue = curRechargeValue + addValue  | 
|         PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ManyDayRechargeValue % (actNum, dayIndex), updRechargeValue)  | 
|         Sync_ManyDayRechargePlayerInfo(curPlayer, actNum)  | 
|         GameWorld.DebugLog("¶àÈÕÁ¬³ä³äÖµ»î¶¯Ôö¼Ó³äÖµ¶î¶È: actNum=%s,dayIndex=%s,curRechargeValue=%s,addValue=%s,updRechargeValue=%s"   | 
|                            % (actNum, dayIndex, curRechargeValue, addValue, updRechargeValue), curPlayer.GetPlayerID())  | 
|           | 
|     return  | 
|   | 
| def OnGetManyDayRechargeAward(curPlayer, awardIndex, actNum):  | 
|     '''OnGetManyDayRechargeAward  | 
|     @param awardIndex: ½±ÀøË÷Òý  | 
|     @param actNum: »î¶¯±àºÅ£¬Èç11 »ò  12 ´ú±í²»Í¬µÄ»î¶¯  | 
|     '''  | 
|     actNum = GameWorld.ToIntDef(actNum, 0)  | 
|     if actNum <= 0:  | 
|         GameWorld.DebugLog("ûÓÐÖ¸¶¨ÁìÈ¡µÄ»î¶¯±àºÅ! actNum=%s" % actNum)  | 
|         return  | 
|       | 
|     playerID = curPlayer.GetPlayerID()  | 
|     actInfo = GameWorld.GetActInfo(ShareDefine.OperationActionName_ManyDayRecharge, actNum)  | 
|       | 
|     state = actInfo.get(ShareDefine.ActKey_State, 0)  | 
|     templateID = GetTemplateID(actInfo.get(ShareDefine.ActKey_CfgID, 0))  | 
|     if not state or not templateID:  | 
|         GameWorld.DebugLog("¸Ã¶àÈÕÁ¬³ä»î¶¯·Ç»î¶¯ÖУ¬ÎÞ·¨Áì½±£¡actNum=%s,state=%s,templateID=%s" % (actNum, state, templateID), playerID)  | 
|         return  | 
|       | 
|     awardRecord = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ManyDayRechargeAward % actNum)  | 
|     if awardRecord & pow(2, awardIndex):  | 
|         GameWorld.DebugLog("ÒѾÁìÈ¡¹ý¸Ã¶àÈÕÁ¬³ä»î¶¯½±Àø! actNum=%s,awardIndex=%s" % (actNum, awardIndex), playerID)  | 
|         return  | 
|       | 
|     ipyDataList = IpyGameDataPY.GetIpyGameDataList("ActManyDayRechargeAward", templateID)  | 
|     if not ipyDataList:  | 
|         return  | 
|       | 
|     awardIpyData = None  | 
|     for ipyData in ipyDataList:  | 
|         if ipyData.GetAwardIndex() == awardIndex:  | 
|             awardIpyData = ipyData  | 
|             break  | 
|           | 
|     if not awardIpyData:  | 
|         GameWorld.DebugLog("ÕÒ²»µ½¸Ã¶àÈÕÁ¬³ä»î¶¯µµÎ»Ë÷Òý½±Àø!actNum=%s,templateID=%s,awardIndex=%s" % (actNum, templateID, awardIndex), playerID)  | 
|         return  | 
|       | 
|     needRechargeValue = CommFunc.RMBToCoin(awardIpyData.GetNeedRMB())  | 
|     needDays = awardIpyData.GetNeedDays()  | 
|       | 
|     dayRechargeValueDict = {}  | 
|     finishDays = 0  | 
|     for dayIndex in xrange(Max_ActDays):  | 
|         rechargeValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ManyDayRechargeValue % (actNum, dayIndex))  | 
|         if rechargeValue >= needRechargeValue:  | 
|             finishDays += 1  | 
|               | 
|         if rechargeValue:  | 
|             dayRechargeValueDict[dayIndex] = rechargeValue  | 
|               | 
|     if finishDays < needDays:  | 
|         GameWorld.DebugLog("δÂú×ã¶àÈÕÁ¬³äµµ´ÎÁ¬³äÌìÊý! templateID=%s,needRechargeValue=%s,needDays(%s) > finishDays(%s), %s"   | 
|                            % (templateID, needRechargeValue, needDays, finishDays, dayRechargeValueDict), playerID)  | 
|         return  | 
|       | 
|     actWorldLV = actInfo.get(ShareDefine.ActKey_WorldLV, 0)          | 
|     awardItemList = GameWorld.GetDictValueByRangeKey(ipyData.GetAwardItemInfo(), actWorldLV, [])  | 
|       | 
|     if not ItemControler.CheckPackSpaceEnough(curPlayer, awardItemList):  | 
|         return  | 
|       | 
|     awardRecord |= pow(2, awardIndex)  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ManyDayRechargeAward % actNum, awardRecord)  | 
|     Sync_ManyDayRechargePlayerInfo(curPlayer, actNum)  | 
|       | 
|     notifyKey = awardIpyData.GetNotifyKey()  | 
|     GameWorld.DebugLog("    ÁìÈ¡³É¹¦! actNum=%s,templateID=%s,awardIndex=%s,needRechargeValue=%s,needDays=%s %s"   | 
|                        % (actNum, templateID, awardIndex, needRechargeValue, needDays, dayRechargeValueDict))  | 
|     if notifyKey:  | 
|         PlayerControl.WorldNotify(0, notifyKey, [curPlayer.GetPlayerName(), needDays, str(awardIpyData.GetNeedRMB())])  | 
|           | 
|     for itemID, itemCount, isAuctionItem in awardItemList:  | 
|         ItemControler.GivePlayerItem(curPlayer, itemID, itemCount, isAuctionItem, [IPY_GameWorld.rptItem])  | 
|           | 
|     addDataDict = {"TemplateID":templateID, "AwardIndex":awardIndex, "ItemList":str(awardItemList), "ActNum":actNum}  | 
|     DataRecordPack.DR_FuncGiveItem(curPlayer, "ManyDayRechargeAward", addDataDict)  | 
|     return  | 
|   | 
| def Sync_ManyDayRechargePlayerInfo(curPlayer, actNum):  | 
|     ## Í¨ÖªÍæ¼ÒÊý¾ÝÐÅÏ¢  | 
|     playerActInfo = ChPyNetSendPack.tagMCActManyDayRechargePlayerInfo()  | 
|     playerActInfo.ActNum = actNum  | 
|     playerActInfo.DayRechargeValues = []  | 
|     for dayIndex in xrange(Max_ActDays):  | 
|         rechargeValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ManyDayRechargeValue % (actNum, dayIndex))  | 
|         playerActInfo.DayRechargeValues.append(rechargeValue)  | 
|     playerActInfo.Days = len(playerActInfo.DayRechargeValues)  | 
|     playerActInfo.AwardRecord = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ManyDayRechargeAward % actNum)  | 
|     NetPackCommon.SendFakePack(curPlayer, playerActInfo)  | 
|     return  | 
|   | 
| def Sync_ManyDayRechargeActionInfo(curPlayer, actNum):  | 
|     ## Í¨Öª»î¶¯ÐÅÏ¢  | 
|       | 
|     actInfo = GameWorld.GetActInfo(ShareDefine.OperationActionName_ManyDayRecharge, actNum)  | 
|     if not actInfo.get(ShareDefine.ActKey_State):  | 
|         return  | 
|       | 
|     cfgID = actInfo.get(ShareDefine.ActKey_CfgID)  | 
|     ipyData = IpyGameDataPY.GetIpyGameData("ActManyDayRecharge", cfgID)  | 
|     if not ipyData:  | 
|         return  | 
|       | 
|     templateID = ipyData.GetTemplateID()  | 
|     if not templateID:  | 
|         return  | 
|       | 
|     actWorldLV = actInfo.get(ShareDefine.ActKey_WorldLV, 0)  | 
|     openServerDay = GameWorld.GetGameWorld().GetGameWorldDictByKey(ShareDefine.Def_Notify_WorldKey_ServerDay) + 1  | 
|       | 
|     clientPack = ChPyNetSendPack.tagMCActManyDayRechargeInfo()  | 
|     clientPack.ActNum = actNum  | 
|     clientPack.StartDate = GameWorld.GetOperationActionDateStr(ipyData.GetStartDate(), openServerDay)  | 
|     clientPack.EndtDate = GameWorld.GetOperationActionDateStr(ipyData.GetEndDate(), openServerDay)  | 
|     clientPack.LimitLV = ipyData.GetLVLimit()  | 
|     clientPack.AwardList = []  | 
|       | 
|     ipyDataList = IpyGameDataPY.GetIpyGameDataList("ActManyDayRechargeAward", templateID)  | 
|     if ipyDataList:  | 
|         for awardIpyData in ipyDataList:  | 
|             awardInfo = ChPyNetSendPack.tagMCActManyDayRechargeAward()  | 
|             awardInfo.AwardIndex = awardIpyData.GetAwardIndex()  | 
|             awardInfo.NeedRecharge = CommFunc.RMBToCoin(awardIpyData.GetNeedRMB())  | 
|             awardInfo.NeedDays = awardIpyData.GetNeedDays()  | 
|             awardInfo.AwardItemList = []  | 
|             awardItemList = GameWorld.GetDictValueByRangeKey(awardIpyData.GetAwardItemInfo(), actWorldLV, [])  | 
|             for itemID, itemCount, isBind in awardItemList:  | 
|                 awardItem = ChPyNetSendPack.tagMCActManyDayRechargeItem()  | 
|                 awardItem.ItemID = itemID  | 
|                 awardItem.ItemCount = itemCount  | 
|                 awardItem.IsBind = isBind  | 
|                 awardInfo.AwardItemList.append(awardItem)  | 
|             awardInfo.AwardItemCount = len(awardInfo.AwardItemList)  | 
|               | 
|             clientPack.AwardList.append(awardInfo)  | 
|               | 
|     clientPack.AwardCount = len(clientPack.AwardList)  | 
|     NetPackCommon.SendFakePack(curPlayer, clientPack)  | 
|     return  | 
|   |