| #!/usr/bin/python  | 
| # -*- coding: GBK -*-  | 
| #-------------------------------------------------------------------------------  | 
| #  | 
| ##@package Player.PlayerFuncSysPrivilege  | 
| #  | 
| # @todo:¹¦ÄÜÏµÍ³ÌØÈ¨½±Àø  | 
| # @author hxp  | 
| # @date 2021-04-13  | 
| # @version 1.0  | 
| #  | 
| # ÏêϸÃèÊö: ¹¦ÄÜÏµÍ³ÌØÈ¨½±Àø  | 
| #  | 
| #-------------------------------------------------------------------------------  | 
| #"""Version = 2021-04-13 16:00"""  | 
| #-------------------------------------------------------------------------------  | 
|   | 
| import GameWorld  | 
| import IpyGameDataPY  | 
| import PlayerControl  | 
| import ItemControler  | 
| import ChPyNetSendPack  | 
| import NetPackCommon  | 
| import IPY_GameWorld  | 
| import ShareDefine  | 
| import ChConfig  | 
|   | 
| import time  | 
|   | 
| def OnPlayerLogin(curPlayer):  | 
|     Sync_FuncSysPrivilege(curPlayer)  | 
|     return  | 
|   | 
| #// B2 11 ¼¤»î¹¦ÄÜÏµÍ³ÌØÈ¨½±Àø #tagCMActivateFuncSysPrivilege  | 
| #  | 
| #struct    tagCMActivateFuncSysPrivilege  | 
| #{  | 
| #    tagHead         Head;  | 
| #    BYTE        ActivateCount;    // ¼¤»î¸öÊý  | 
| #    BYTE        ActivateFuncSysIDList[ActivateCount];    // ¼¤»î¹¦ÄÜϵͳIDÁÐ±í£¬È«²¿¼¤»îÔòÐèÒª·¢ËùÓÐIDÁÐ±í  | 
| #};  | 
| def OnActivateFuncSysPrivilege(index, clientData, tick):  | 
|     curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)  | 
|     activateFuncSysIDList = clientData.ActivateFuncSysIDList  | 
|       | 
|     GameWorld.DebugLog("ÇëÇ󼤻ÄÜÏµÍ³ÌØÈ¨: %s" % activateFuncSysIDList)  | 
|       | 
|     curTime = int(time.time())  | 
|     canActivateList = []  | 
|     for funcSysID in activateFuncSysIDList:  | 
|         ipyDatList = IpyGameDataPY.GetIpyGameDataList("FuncSysPrivilege", funcSysID)  | 
|         if not ipyDatList:  | 
|             continue  | 
|           | 
|         actTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FuncSysPrivilegeActTime % funcSysID)  | 
|         if actTime:  | 
|             maxDays = len(ipyDatList)  | 
|             diffDays = GameWorld.GetDiff_Day(curTime, actTime)  | 
|             if diffDays < maxDays:  | 
|                 GameWorld.DebugLog("    Î´³¬¹ý½±Àø×î´óÌ죬²»¿É¼¤»î: funcSysID=%s,diffDays(%s) < maxDays(%s)" % (funcSysID, diffDays, maxDays))  | 
|                 continue  | 
|               | 
|             isGetAll = True  | 
|             awardState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FuncSysPrivilegeAward % funcSysID)  | 
|             for ipyData in ipyDatList:  | 
|                 dayNum = ipyData.GetDayNum()  | 
|                 if not awardState & pow(2, dayNum):  | 
|                     isGetAll = False  | 
|                     GameWorld.DebugLog("    »¹ÓÐδÁìÈ¡µÄ½±Àø£¬²»¿É¼¤»î: funcSysID=%s,dayNum=%s" % (funcSysID, dayNum))  | 
|                     break  | 
|                   | 
|             if not isGetAll:  | 
|                 continue  | 
|         canActivateList.append(funcSysID)  | 
|           | 
|     GameWorld.DebugLog("    ¿É¼¤»îµÄ¹¦ÄÜÏµÍ³ÌØÈ¨: %s" % canActivateList)  | 
|     if not canActivateList:  | 
|         return  | 
|       | 
|     needMoney = len(canActivateList) # ¿ªÍ¨1¸ö»¨·Ñ1  | 
|     infoDict = {ChConfig.Def_Cost_Reason_SonKey:canActivateList}  | 
|     if not PlayerControl.PayMoney(curPlayer, ShareDefine.TYPE_Price_FuncSysPrivilege, needMoney, infoDict=infoDict):  | 
|         GameWorld.DebugLog("    »õ±Ò²»×ã! needMoney=%s" % needMoney)  | 
|         return  | 
|       | 
|     for funcSysID in canActivateList:  | 
|         PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FuncSysPrivilegeActTime % funcSysID, curTime)  | 
|         PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FuncSysPrivilegeAward % funcSysID, 0)  | 
|           | 
|     Sync_FuncSysPrivilege(curPlayer, canActivateList)  | 
|     return  | 
|   | 
| #// B2 12 ÁìÈ¡¹¦ÄÜÏµÍ³ÌØÈ¨½±Àø #tagCMGetFuncSysPrivilegeAward  | 
| #  | 
| #struct    tagCMGetFuncSysPrivilegeAward  | 
| #{  | 
| #    tagHead         Head;  | 
| #    BYTE        FuncSysID;    // ¹¦ÄÜϵͳID  | 
| #    BYTE        DayNum;        // µÚXÌ죬1ΪµÚ1Ìì  | 
| #};  | 
| def OnGetFuncSysPrivilegeAward(index, clientData, tick):  | 
|     curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)  | 
|     funcSysID = clientData.FuncSysID  | 
|     dayNum = clientData.DayNum  | 
|       | 
|     actTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FuncSysPrivilegeActTime % funcSysID)  | 
|     if not actTime:  | 
|         GameWorld.DebugLog("δ¼¤»î£¬²»¿ÉÁì½±£¡funcSysID=%s" % (funcSysID))  | 
|         return  | 
|       | 
|     curTime = int(time.time())  | 
|     canGetMaxDayNum = GameWorld.GetDiff_Day(curTime, actTime) + 1  | 
|     if dayNum > canGetMaxDayNum:  | 
|         GameWorld.DebugLog("δ´ïµ½Áì½±Ì죬²»¿ÉÁì½±£¡funcSysID=%s,dayNum(%s) > canGetMaxDayNum(%s), actTime=%s"   | 
|                            % (funcSysID, dayNum, canGetMaxDayNum, GameWorld.ChangeTimeNumToStr(actTime)))  | 
|         return  | 
|       | 
|     awardState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FuncSysPrivilegeAward % funcSysID)  | 
|     if awardState & pow(2, dayNum):  | 
|         GameWorld.DebugLog("ÒÑÁìÈ¡¹ý¸ÃÌì½±Àø£¡funcSysID=%s,dayNum=%s,awardState=%s" % (funcSysID, dayNum, awardState))  | 
|         return  | 
|       | 
|     ipyDatList = IpyGameDataPY.GetIpyGameDataList("FuncSysPrivilege", funcSysID)  | 
|     if not ipyDatList:  | 
|         return  | 
|       | 
|     findIpyData = None  | 
|     for ipyData in ipyDatList:  | 
|         if ipyData.GetFuncSysID() == funcSysID and ipyData.GetDayNum() == dayNum:  | 
|             findIpyData = ipyData  | 
|             break  | 
|     if not findIpyData:  | 
|         GameWorld.DebugLog("ÕÒ²»µ½¸ÃÌì½±Àø£¡funcSysID=%s,dayNum=%s" % (funcSysID, dayNum))  | 
|         return  | 
|       | 
|     awardItemList = findIpyData.GetDayAwardItemInfo()  | 
|     if not ItemControler.CheckPackSpaceEnough(curPlayer, awardItemList):  | 
|         return  | 
|       | 
|     updAwardState = awardState | pow(2, dayNum)  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FuncSysPrivilegeAward % funcSysID, updAwardState)  | 
|       | 
|     for itemID, itemCount, isAuctionItem in awardItemList:  | 
|         ItemControler.GivePlayerItem(curPlayer, itemID, itemCount, isAuctionItem, [IPY_GameWorld.rptItem],   | 
|                                      event=["FuncSysPrivilegeAward", False, {}])  | 
|           | 
|     Sync_FuncSysPrivilege(curPlayer, [funcSysID])  | 
|     return  | 
|   | 
| def Sync_FuncSysPrivilege(curPlayer, syncIDList=None):  | 
|     if syncIDList == None:  | 
|         syncIDList = []  | 
|         ipyDataMgr = IpyGameDataPY.IPY_Data()  | 
|         lastIpyData = ipyDataMgr.GetFuncSysPrivilegeByIndex(ipyDataMgr.GetFuncSysPrivilegeCount() - 1)  | 
|         maxFuncID = lastIpyData.GetFuncSysID()  | 
|         for funcSysID in xrange(1, maxFuncID + 1):  | 
|             if curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FuncSysPrivilegeActTime % funcSysID):  | 
|                 syncIDList.append(funcSysID)  | 
|           | 
|         if not syncIDList:  | 
|             return  | 
|           | 
|     clientPack = ChPyNetSendPack.tagMCFuncSysPrivilegeInfoList()  | 
|     clientPack.PrivilegeInfoList = []  | 
|     for funcSysID in syncIDList:  | 
|         info = ChPyNetSendPack.tagMCFuncSysPrivilegeInfo()  | 
|         info.FuncSysID = funcSysID  | 
|         info.ActivateTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FuncSysPrivilegeActTime % funcSysID)  | 
|         info.AwardState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FuncSysPrivilegeAward % funcSysID)  | 
|           | 
|         clientPack.PrivilegeInfoList.append(info)  | 
|     clientPack.PrivilegeCount = len(clientPack.PrivilegeInfoList)  | 
|     NetPackCommon.SendFakePack(curPlayer, clientPack)  | 
|     return  | 
|   | 
|   |