| #!/usr/bin/python  | 
| # -*- coding: GBK -*-  | 
| #-------------------------------------------------------------------------------  | 
| #  | 
| ##@package Player.PlayerCustomAward  | 
| #  | 
| # @todo:×Ô¶¨Òå½±Àø  | 
| # @author hxp  | 
| # @date 2023-09-22  | 
| # @version 1.0  | 
| #  | 
| # ÏêϸÃèÊö: ×Ô¶¨Òå½±Àø  | 
| #  | 
| #-------------------------------------------------------------------------------  | 
| #"""Version = 2023-09-22 13:30"""  | 
| #-------------------------------------------------------------------------------  | 
|   | 
| import GameWorld  | 
| import NetPackCommon  | 
| import ChPyNetSendPack  | 
| import IpyGameDataPY  | 
| import ItemCommon  | 
| import ChConfig  | 
|   | 
| def OnPlayerLogin(curPlayer):  | 
|     Sync_CustomAwardInfo(curPlayer)  | 
|     return  | 
|   | 
| def SetCustomAwardCanGet(curPlayer, awardID, canGet=1):  | 
|     ipyData = IpyGameDataPY.GetIpyGameData("CustomAward", awardID)  | 
|     if not ipyData:  | 
|         return  | 
|     GameWorld.SetDictValueByBit(curPlayer, ChConfig.Def_PDict_CustomAwardCanGet, awardID, canGet)  | 
|     Sync_CustomAwardInfo(curPlayer, awardID)  | 
|     return  | 
|   | 
| ## ÁìÈ¡×Ô¶¨Òå½±Àø  | 
| def OnGetCustomAward(curPlayer, awardID):  | 
|     if not GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_CustomAwardCanGet, awardID):  | 
|         GameWorld.Log("¸Ã×Ô¶¨Òå½±Àøµ±Ç°²»¿ÉÁìÈ¡, awardID=%s" % awardID, curPlayer.GetPlayerID())  | 
|         return  | 
|     if GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_CustomAwardGetState, awardID):  | 
|         GameWorld.Log("¸Ã×Ô¶¨Òå½±ÀøÒѾÁìÈ¡¹ý, awardID=%s" % awardID, curPlayer.GetPlayerID())  | 
|         return  | 
|     ipyData = IpyGameDataPY.GetIpyGameData("CustomAward", awardID)  | 
|     if not ipyData:  | 
|         return  | 
|     awardItemList = ipyData.GetAwardItemList()  | 
|       | 
|     if not ItemCommon.GiveAwardItem(curPlayer, awardItemList, "CustomAward"):  | 
|         return  | 
|       | 
|     GameWorld.SetDictValueByBit(curPlayer, ChConfig.Def_PDict_CustomAwardGetState, awardID, 1)  | 
|     GameWorld.Log("ÁìÈ¡×Ô¶¨Òå½±Àø, awardID=%s" % awardID, curPlayer.GetPlayerID())  | 
|     Sync_CustomAwardInfo(curPlayer, awardID)  | 
|     return  | 
|   | 
| ## Í¨Öª×Ô¶¨Òå½±Àø¼Ç¼  | 
| def Sync_CustomAwardInfo(curPlayer, awardID=None, force=False):  | 
|     if awardID == None:  | 
|         awardIDList = []  | 
|         ipyDataMgr = IpyGameDataPY.IPY_Data()  | 
|         for index in range(ipyDataMgr.GetCustomAwardCount()):  | 
|             ipyData = ipyDataMgr.GetCustomAwardByIndex(index)  | 
|             awardIDList.append(ipyData.GetAwardID())  | 
|     else:  | 
|         awardIDList = [awardID]  | 
|           | 
|     keyNumList = []  | 
|     for aID in awardIDList:  | 
|         keyNum = GameWorld.GetDictKeyNumByBit(aID)  | 
|         if keyNum not in keyNumList:  | 
|             keyNumList.append(keyNum)  | 
|       | 
|     if not keyNumList:  | 
|         return  | 
|       | 
|     recordStateList = []  | 
|     for keyNum in keyNumList:  | 
|         canGet = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CustomAwardCanGet % keyNum)  | 
|         getState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CustomAwardGetState % keyNum)  | 
|         if not canGet and not getState and not force:  | 
|             continue  | 
|         awardState = ChPyNetSendPack.tagMCCustomAwardState()  | 
|         awardState.KeyNum = keyNum  | 
|         awardState.CanGetState = canGet  | 
|         awardState.GetState = getState  | 
|         recordStateList.append(awardState)  | 
|           | 
|     if not recordStateList:  | 
|         return  | 
|       | 
|     clientPack = ChPyNetSendPack.tagMCCustomAwardInfo()  | 
|     clientPack.Clear()  | 
|     clientPack.RecordStateList = recordStateList  | 
|     clientPack.RecordStateCnt = len(clientPack.RecordStateList)  | 
|     NetPackCommon.SendFakePack(curPlayer, clientPack)  | 
|     return  |