| #!/usr/bin/python  | 
| # -*- coding: GBK -*-  | 
| #-------------------------------------------------------------------------------  | 
| #  | 
| ##@package Player.PlayerActXianXiaMJ  | 
| #  | 
| # @todo:ÏÉÏ»ÃØ¾³  | 
| # @author hxp  | 
| # @date 2021-05-26  | 
| # @version 1.0  | 
| #  | 
| # ÏêϸÃèÊö: ÏÉÏ»ÃØ¾³  | 
| #  | 
| #-------------------------------------------------------------------------------  | 
| #"""Version = 2021-05-26 11:30"""  | 
| #-------------------------------------------------------------------------------  | 
|   | 
| import PyGameData  | 
| import ShareDefine  | 
| import PlayerControl  | 
| import IpyGameDataPY  | 
| import ItemControler  | 
| import ChPyNetSendPack  | 
| import NetPackCommon  | 
| import GameWorld  | 
| import ChConfig  | 
|   | 
| Def_SuperLibType = 9 # ´ó½±¿âÀàÐ͹̶¨Îª9  | 
|   | 
| def OnPlayerLogin(curPlayer):  | 
|       | 
|     for actInfo in PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_XianXiaMJ, {}).values():  | 
|         actNum = actInfo.get(ShareDefine.ActKey_ActNum, 0)  | 
|         isReset = __CheckPlayerXianXiaMJAction(curPlayer, actNum)  | 
|         if not isReset:  | 
|             # »î¶¯ÖÐͬ²½»î¶¯ÐÅÏ¢  | 
|             if actInfo.get(ShareDefine.ActKey_State):  | 
|                 Sync_XianXiaMJActionInfo(curPlayer, actNum)  | 
|     return  | 
|   | 
| def RefreshXianXiaMJActionInfo(actNum):  | 
|     ## ÊÕµ½GameServerͬ²½µÄ»î¶¯ÐÅÏ¢£¬Ë¢Ð»ÐÅÏ¢  | 
|     playerManager = GameWorld.GetPlayerManager()  | 
|     for index in xrange(playerManager.GetPlayerCount()):  | 
|         curPlayer = playerManager.GetPlayerByIndex(index)  | 
|         if curPlayer.GetID() == 0:  | 
|             continue  | 
|         __CheckPlayerXianXiaMJAction(curPlayer, actNum)  | 
|     return  | 
|   | 
| def __CheckPlayerXianXiaMJAction(curPlayer, actNum):  | 
|     ## ¼ì²éÍæ¼Ò»î¶¯Êý¾ÝÐÅÏ¢  | 
|       | 
|     playerID = curPlayer.GetPlayerID()  | 
|     actInfo = GameWorld.GetActInfo(ShareDefine.OperationActionName_XianXiaMJ, actNum)  | 
|     actID = actInfo.get(ShareDefine.ActKey_ID, 0)  | 
|     state = actInfo.get(ShareDefine.ActKey_State, 0)  | 
|     cfgID = actInfo.get(ShareDefine.ActKey_CfgID, 0)  | 
|       | 
|     playerActID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_XianXiaMJID % actNum) # Íæ¼ÒÉíÉϵĻID  | 
|       | 
|     # »î¶¯ID ÏàͬµÄ»°²»´¦Àí  | 
|     if actID == playerActID:  | 
|         GameWorld.DebugLog("ÏÉÏ»ÃØ¾³»î¶¯ID²»±ä£¬²»´¦Àí£¡actNum=%s,actID=%s" % (actNum, actID), playerID)  | 
|           | 
|         layerInfoValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_XianXiaMJAwardLayerInfo % actNum)  | 
|         layerNum = layerInfoValue % 100  | 
|         if state and layerNum <= 0:  | 
|             GameWorld.Log("ÏÉÏ»ÃØ¾³»î¶¯Öе«Êײ㽱³ØÎ´Ë¢Ð³õʼ»¯£¬³¢ÊÔˢУ¡actNum=%s,actID=%s" % (actNum, actID), playerID)  | 
|             __InitFirstLayerData(curPlayer, actNum, actInfo)  | 
|               | 
|         return  | 
|       | 
|     actWorldLV = actInfo.get(ShareDefine.ActKey_WorldLV, 0)  | 
|       | 
|     GameWorld.DebugLog("ÏÉÏ»ÃØ¾³ÖØÖÃ! actNum=%s,actID=%s,playerActID=%s,state=%s,cfgID=%s"   | 
|                        % (actNum, actID, playerActID, state, cfgID), playerID)  | 
|       | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_XianXiaMJID % actNum, actID)  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_XianXiaMJWorldLV % actNum, actWorldLV)  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_XianXiaMJAwardLayerInfo % actNum, 0)  | 
|       | 
|     __InitFirstLayerData(curPlayer, actNum, actInfo)  | 
|     return True  | 
|   | 
| def __InitFirstLayerData(curPlayer, actNum, actInfo):  | 
|     ## ³õʼ»¯ÊײãÊý¾Ý  | 
|       | 
|     state = actInfo.get(ShareDefine.ActKey_State, 0)  | 
|     cfgID = actInfo.get(ShareDefine.ActKey_CfgID, 0)  | 
|       | 
|     ipyData = IpyGameDataPY.GetIpyGameData("ActXianXiaMJ", cfgID) if cfgID else None  | 
|     templateID = ipyData.GetTemplateID() if ipyData else 0  | 
|     awardIpyDataList = IpyGameDataPY.GetIpyGameDataList("ActXianXiaMJAward", templateID) if templateID else []  | 
|     if awardIpyDataList:  | 
|         for awardIpyData in awardIpyDataList:  | 
|             libType = awardIpyData.GetAwardLibType()  | 
|             libItemCount = awardIpyData.GetAwardItemCount()  | 
|             for num in xrange(libItemCount):  | 
|                 PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_XianXiaMJAwardItemInfo % (actNum, libType, num), 0)  | 
|                   | 
|             itemAwardTimesTotalInfo = awardIpyData.GetItemAwardTimesTotalInfo()  | 
|             for itemID in itemAwardTimesTotalInfo.keys():  | 
|                 PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_XianXiaMJAwardItemTimes % (actNum, libType, itemID), 0)  | 
|                   | 
|         # »î¶¯ÖУ¬Éú³Éн±³Ø      | 
|         if state:  | 
|             __RefreshXianXiaMJAwardPool(curPlayer, actInfo, awardIpyDataList)  | 
|               | 
|     Sync_XianXiaMJActionInfo(curPlayer, actNum)  | 
|     return True  | 
|   | 
| #// AA 16 ÏÉÏ»ÃØ¾³»î¶¯Ñ¡Ôñ´ó½± #tagCMActXianXiaMJSuperItem  | 
| #  | 
| #struct    tagCMActXianXiaMJSuperItem  | 
| #{  | 
| #    tagHead        Head;  | 
| #    BYTE        ActNum;        //»î¶¯±àºÅ  | 
| #    BYTE        SuperItemCount;    //Ñ¡ÔñÎïÆ·ÊýÁ¿  | 
| #    DWORD        SuperItemIDList[SuperItemCount];    //Ñ¡ÔñµÄ´ó½±¿âÎïÆ·IDÁÐ±í£¬Ã¿´ÎÖØÐÂÑ¡ÔñÐèÒª·¢ËÍÈ«²¿ÒÑÑ¡ÔñµÄ´ó½±ÎïÆ·ID£¬²»ÄÜÖ»·¢µ¥¸öÎïÆ·ID;  | 
| #};  | 
| def OnActXianXiaMJSuperItem(index, clientData, tick):  | 
|     curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)  | 
|     actNum = clientData.ActNum  | 
|     superItemIDList = clientData.SuperItemIDList  | 
|       | 
|     GameWorld.DebugLog("ÏÉÏ»ÃØ¾³»î¶¯Ñ¡Ôñ´ó½±: actNum=%s,superItemIDList=%s" % (actNum, superItemIDList))  | 
|       | 
|     actInfo = GameWorld.GetActInfo(ShareDefine.OperationActionName_XianXiaMJ, actNum)  | 
|     if not actInfo.get(ShareDefine.ActKey_State):  | 
|         GameWorld.DebugLog("    ·Ç»î¶¯ÖÐ!")  | 
|         return  | 
|       | 
|     cfgID = actInfo.get(ShareDefine.ActKey_CfgID)  | 
|     ipyData = IpyGameDataPY.GetIpyGameData("ActXianXiaMJ", cfgID)  | 
|     if not ipyData:  | 
|         return  | 
|       | 
|     templateID = ipyData.GetTemplateID()  | 
|     if not templateID:  | 
|         return  | 
|       | 
|     actWorldLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_XianXiaMJWorldLV % actNum)  | 
|     awardIpyDataList = IpyGameDataPY.GetIpyGameDataList("ActXianXiaMJAward", templateID)  | 
|     if not awardIpyDataList:  | 
|         return  | 
|       | 
|     superAwardIpyData = None  | 
|     for awardIpyData in awardIpyDataList:  | 
|         libType = awardIpyData.GetAwardLibType()  | 
|         if libType == Def_SuperLibType:  | 
|             superAwardIpyData = awardIpyData  | 
|             break  | 
|       | 
|     if not superAwardIpyData:  | 
|         GameWorld.ErrLog("ûÓÐÅäÖÃÏÉÏ»ÃØ¾³»î¶¯´ó½±¿â! cfgID=%s,actNum=%s,templateID=%s" % (cfgID, actNum, templateID))  | 
|         return  | 
|       | 
|     superLibItemCount = superAwardIpyData.GetAwardItemCount()  | 
|     if len(superItemIDList) != superLibItemCount:  | 
|         GameWorld.ErrLog("ÏÉÏ»ÃØ¾³»î¶¯Ñ¡Ôñ´ó½±¸öÊý´íÎó! cfgID=%s,actNum=%s,templateID=%s,superLibItemCount=%s,reqSuperItemIDList=%s"   | 
|                          % (cfgID, actNum, templateID, superLibItemCount, superItemIDList))          | 
|         return  | 
|       | 
|     posNumItemIDList = [] # ÒѳéÖеĴó½±ÎïÆ·ID  | 
|     libType = superAwardIpyData.GetAwardLibType()  | 
|     for num in xrange(superLibItemCount):  | 
|         itemInfoValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_XianXiaMJAwardItemInfo % (actNum, libType, num))  | 
|         if not itemInfoValue:  | 
|             break  | 
|         itemID, posNum = itemInfoValue / 100, itemInfoValue % 100  | 
|         if posNum and itemID not in superItemIDList:  | 
|             GameWorld.ErrLog("ÏÉÏ»ÃØ¾³»î¶¯Ñ¡Ôñ´ó½±ID´íÎó! ÒѳéÖеĴó½±IDΪ±ØÑ¡ID£¡ posNum=%s, itemID=%s not in superItemIDList=%s"   | 
|                              % (posNum, itemID, superItemIDList))  | 
|             return  | 
|           | 
|         if posNum:  | 
|             posNumItemIDList.append(itemID)  | 
|               | 
|     GameWorld.DebugLog("    ÒѳéÖеĴó½±ID! %s" % posNumItemIDList)  | 
|       | 
|     layerInfoValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_XianXiaMJAwardLayerInfo % actNum)  | 
|     layerNum = layerInfoValue % 100  | 
|       | 
|     libItemDict = __GetXianXiaMJAwardLibItem(superAwardIpyData.GetLibItemInfo(), actWorldLV)  | 
|     layerLimitInfo = superAwardIpyData.GetItemLayerLimitInfo()  | 
|     awardTimesTotalInfo = superAwardIpyData.GetItemAwardTimesTotalInfo()  | 
|       | 
|     replaceSuperItemIDList = [] # ÐèÒªÌæ»»µÄ´ó½±IDÁÐ±í  | 
|       | 
|     for selectItemID in superItemIDList:  | 
|         if selectItemID in posNumItemIDList:  | 
|             GameWorld.DebugLog("        ÒѳéÖеĴó½±ID£¬²»ÑéÖ¤£¡selectItemID=%s" % (selectItemID))  | 
|             continue  | 
|           | 
|         if selectItemID not in libItemDict:  | 
|             GameWorld.ErrLog("ÏÉÏ»ÃØ¾³»î¶¯Ñ¡Ôñ´ó½±ID´íÎó! ´ó½±ID²»´æÔڴ󽱿âÖУ¡ selectItemID=%s not in libItemDict=%s"   | 
|                              % (selectItemID, libItemDict))  | 
|             return  | 
|           | 
|         layerLimit = layerLimitInfo.get(selectItemID, 0)  | 
|         if layerLimit > layerNum:  | 
|             GameWorld.ErrLog("ÏÉÏ»ÃØ¾³»î¶¯Ñ¡Ôñ´ó½±ID´íÎó! ´ó½±ID¸Ã²ã²»ÄÜÑ¡Ôñ£¡ selectItemID=%s layerLimit(%s) > layerNum(%s)"   | 
|                              % (selectItemID, layerLimit, layerNum))  | 
|             return  | 
|           | 
|         totalTimesLimit = awardTimesTotalInfo.get(selectItemID, 0)  | 
|         if totalTimesLimit:  | 
|             totalTimesNow = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_XianXiaMJAwardItemTimes % (actNum, libType, selectItemID))  | 
|             if totalTimesNow >= totalTimesLimit:  | 
|                 GameWorld.ErrLog("ÏÉÏ»ÃØ¾³»î¶¯Ñ¡Ôñ´ó½±ID´íÎó! ´ó½±IDÒÑ´ïµ½×î´ó½±Àø´ÎÊý£¬²»ÄÜÑ¡Ôñ£¡ selectItemID=%s totalTimesNow(%s) >= totalTimesLimit(%s)"   | 
|                                  % (selectItemID, totalTimesNow, totalTimesLimit))  | 
|                 return  | 
|                   | 
|         replaceSuperItemIDList.append(selectItemID)  | 
|           | 
|     GameWorld.DebugLog("    Ñé֤ͨ¹ý£¬¿ÉÌæ»»´ó½±ID! replaceSuperItemIDList=%s" % replaceSuperItemIDList)  | 
|     if not replaceSuperItemIDList:  | 
|         return  | 
|       | 
|     for num in xrange(superLibItemCount):  | 
|         itemInfoValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_XianXiaMJAwardItemInfo % (actNum, libType, num))  | 
|         itemID, posNum = itemInfoValue / 100, itemInfoValue % 100  | 
|         if itemID in posNumItemIDList:  | 
|             GameWorld.DebugLog("        ÒѳéÖеĴó½±ID£¬²»Ìæ»»£¡itemID=%s" % (itemID))  | 
|             continue  | 
|         replaceSuperItemID = replaceSuperItemIDList.pop(0)  | 
|         updItemInfoValue = replaceSuperItemID * 100 + posNum  | 
|         PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_XianXiaMJAwardItemInfo % (actNum, libType, num), updItemInfoValue)  | 
|         GameWorld.DebugLog("        Ìæ»»´ó½±IDÑ¡Ôñ£¡num=%s,itemID=%s,posNum=%s,replaceSuperItemID=%s,updItemInfoValue=%s"   | 
|                            % (num, itemID, posNum, replaceSuperItemID, updItemInfoValue))  | 
|           | 
|         if not replaceSuperItemIDList:  | 
|             break  | 
|           | 
|     Sync_XianXiaMJActionInfo(curPlayer, actNum)  | 
|     return  | 
|   | 
| #// AA 18 ÏÉÏ»ÃØ¾³»î¶¯½±³ØË¢Ð #tagCMActXianXiaMJAwardPoolRefresh  | 
| #  | 
| #struct    tagCMActXianXiaMJAwardPoolRefresh  | 
| #{  | 
| #    tagHead        Head;  | 
| #    BYTE        ActNum;        //»î¶¯±àºÅ  | 
| #};  | 
| def OnActXianXiaMJAwardPoolRefresh(index, clientData, tick):  | 
|     curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)  | 
|     actNum = clientData.ActNum  | 
|       | 
|     GameWorld.DebugLog("ÏÉÏ»ÃØ¾³»î¶¯½±³ØË¢ÐÂ: actNum=%s" % (actNum))  | 
|       | 
|     actInfo = GameWorld.GetActInfo(ShareDefine.OperationActionName_XianXiaMJ, actNum)  | 
|     if not actInfo.get(ShareDefine.ActKey_State):  | 
|         GameWorld.DebugLog("    ·Ç»î¶¯ÖÐ!")  | 
|         return  | 
|       | 
|     cfgID = actInfo.get(ShareDefine.ActKey_CfgID)  | 
|     ipyData = IpyGameDataPY.GetIpyGameData("ActXianXiaMJ", cfgID)  | 
|     if not ipyData:  | 
|         return  | 
|       | 
|     templateID = ipyData.GetTemplateID()  | 
|     if not templateID:  | 
|         return  | 
|       | 
|     awardIpyDataList = IpyGameDataPY.GetIpyGameDataList("ActXianXiaMJAward", templateID)  | 
|     if not awardIpyDataList:  | 
|         return  | 
|       | 
|     if not __RefreshXianXiaMJAwardPool(curPlayer, actInfo, awardIpyDataList):  | 
|         return  | 
|       | 
|     Sync_XianXiaMJActionInfo(curPlayer, actNum)  | 
|     return  | 
|   | 
| def __RefreshXianXiaMJAwardPool(curPlayer, actInfo, awardIpyDataList):  | 
|     ## Ë¢Ð½±³ØÎïÆ·  | 
|       | 
|     cfgID = actInfo.get(ShareDefine.ActKey_CfgID)  | 
|     actNum = actInfo.get(ShareDefine.ActKey_ActNum, 0)  | 
|     actWorldLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_XianXiaMJWorldLV % actNum)  | 
|       | 
|     layerInfoValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_XianXiaMJAwardLayerInfo % actNum)  | 
|     layerNum = layerInfoValue % 100  | 
|       | 
|     GameWorld.DebugLog("Ë¢ÐÂÏÉÏ»ÃØ¾³½±³ØÎïÆ·: cfgID=%s,actNum=%s,actWorldLV=%s,layerNum=%s" % (cfgID, actNum, actWorldLV, layerNum))  | 
|       | 
|     if layerNum:  | 
|         # ·Ç0²ã£¬ÑéÖ¤´ó½±ÊÇ·ñÒѳéÍ꣬³éÍê²Å¿ÉÒÔˢн±³Ø²ã  | 
|         superLib = False  | 
|         for awardIpyData in awardIpyDataList:  | 
|             libType = awardIpyData.GetAwardLibType()  | 
|             if libType != Def_SuperLibType:  | 
|                 continue  | 
|             superLib = True  | 
|             libItemCount = awardIpyData.GetAwardItemCount()  | 
|             for num in xrange(libItemCount):  | 
|                 itemInfoValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_XianXiaMJAwardItemInfo % (actNum, libType, num))  | 
|                 itemID, posNum = itemInfoValue / 100, itemInfoValue % 100  | 
|                 if itemID and not posNum:  | 
|                     GameWorld.ErrLog("Óдó½±Î´³éÖУ¡ÎÞ·¨Ë¢Ð½±³Ø! cfgID=%s,actNum=%s,layerNum=%s,num=%s,itemID=%s,posNum=%s"   | 
|                                      % (cfgID, actNum, layerNum, num, itemID, posNum))  | 
|                     return  | 
|             break  | 
|         if not superLib:  | 
|             GameWorld.ErrLog("½±³ØÅäÖÃûÓд󽱿⣡ÎÞ·¨Ë¢Ð½±³Ø! cfgID=%s,actNum=%s,layerNum=%s,superLib=%s" % (cfgID, actNum, layerNum, superLib))  | 
|             return  | 
|           | 
|     layerNum += 1 # ¿Éˢн±³Ø£¬Ä¬ÈÏ+1²ã  | 
|     if layerNum > 99:  | 
|         GameWorld.ErrLog("½±³Ø²ãÊý´ïµ½ÉÏÏÞ£¬ÎÞ·¨Ë¢ÐÂ! cfgID=%s,actNum=%s,layerNum=%s" % (cfgID, actNum, layerNum))  | 
|         return  | 
|     GameWorld.DebugLog("    ¿Éˢн±³Ø£¡ÏÂÒ»²ã: layerNum=%s" % (layerNum))  | 
|       | 
|     refreshLibDict = {}  | 
|     for awardIpyData in awardIpyDataList:  | 
|         libType = awardIpyData.GetAwardLibType()  | 
|         libItemCount = awardIpyData.GetAwardItemCount()  | 
|         libItemDict = __GetXianXiaMJAwardLibItem(awardIpyData.GetLibItemInfo(), actWorldLV)  | 
|         layerLimitInfo = awardIpyData.GetItemLayerLimitInfo()  | 
|         awardTimesTotalInfo = awardIpyData.GetItemAwardTimesTotalInfo()  | 
|           | 
|         canRandItemDict = {}  | 
|         for itemID, libItemInfo in libItemDict.items():  | 
|             _, weight = libItemInfo  | 
|               | 
|             layerLimit = layerLimitInfo.get(itemID, 0)  | 
|             if layerLimit > layerNum:  | 
|                 GameWorld.DebugLog("        ¸Ã²ã²»ÄÜÑ¡Ôñ¸Ã½±Æ·£¡ itemID=%s layerLimit(%s) > layerNum(%s)"   | 
|                                  % (itemID, layerLimit, layerNum))  | 
|                 continue  | 
|               | 
|             totalTimesLimit = awardTimesTotalInfo.get(itemID, 0)  | 
|             if totalTimesLimit:  | 
|                 totalTimesNow = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_XianXiaMJAwardItemTimes % (actNum, libType, itemID))  | 
|                 if totalTimesNow >= totalTimesLimit:  | 
|                     GameWorld.DebugLog("        ½±Æ·IDÒÑ´ïµ½×î´ó½±Àø´ÎÊý£¬²»ÄÜÑ¡Ôñ£¡ itemID=%s totalTimesNow(%s) >= totalTimesLimit(%s)"   | 
|                                        % (itemID, totalTimesNow, totalTimesLimit))  | 
|                     continue  | 
|                   | 
|             canRandItemDict[itemID] = [weight, itemID]  | 
|               | 
|         if libItemCount > len(canRandItemDict):  | 
|             GameWorld.ErrLog("½±Æ·¿âÅäÖÿÉÑ¡Ôñ½±Æ·¸öÊý²»¹»£¡ÎÞ·¨Ë¢Ð½±³Ø! cfgID=%s,actNum=%s,libType=%s,layerNum=%s,libItemCount=%s > %s canRandItemDict(%s)"   | 
|                              % (cfgID, actNum, libType, layerNum, libItemCount, len(canRandItemDict), canRandItemDict))  | 
|             return  | 
|           | 
|         refreshLibDict[libType] = [libItemCount, canRandItemDict]  | 
|           | 
|     for libType, refreshInfo in refreshLibDict.items():  | 
|         libItemCount, canRandItemDict = refreshInfo  | 
|         GameWorld.DebugLog("    Ëæ»ú½±³ØÎïÆ·: libType=%s,libItemCount=%s,canRandItemDict=%s, %s" % (libType, libItemCount, len(canRandItemDict), canRandItemDict))  | 
|           | 
|         if libType == Def_SuperLibType:  | 
|             # ´ó½±Ö±½ÓÖØÖã¬ÏµÍ³²»Éú³É£¬ÓÉÍæ¼ÒÊÖ¶¯Ñ¡Ôñ  | 
|             for num in xrange(libItemCount):  | 
|                 PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_XianXiaMJAwardItemInfo % (actNum, libType, num), 0)  | 
|             continue  | 
|           | 
|         for num in xrange(libItemCount):  | 
|             weightList = canRandItemDict.values()  | 
|             randItemID = GameWorld.GetResultByWeightList(weightList)  | 
|             canRandItemDict.pop(randItemID, None)  | 
|               | 
|             posNum = 0  | 
|             itemInfoValue = randItemID * 100 + posNum  | 
|             PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_XianXiaMJAwardItemInfo % (actNum, libType, num), itemInfoValue)  | 
|             GameWorld.DebugLog("        Ëæ»úÉú³É½±Æ·! libType=%s,num=%s,randItemID=%s" % (libType, num, randItemID))  | 
|               | 
|     playCount = 0 # Ã¿²ãÖØÖó齱´ÎÊý  | 
|     layerInfoValue = playCount * 100 + layerNum  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_XianXiaMJAwardLayerInfo % actNum, layerInfoValue)  | 
|     GameWorld.DebugLog("    Ë¢ÐÂÍê³É! playCount=%s,layerNum=%s,layerInfoValue=%s" % (playCount, layerNum, layerInfoValue))  | 
|     return True  | 
|   | 
| #// AA 17 ÏÉÏ»ÃØ¾³»î¶¯³é½± #tagCMActXianXiaMJLottery  | 
| #  | 
| #struct    tagCMActXianXiaMJLottery  | 
| #{  | 
| #    tagHead        Head;  | 
| #    BYTE        ActNum;        //»î¶¯±àºÅ  | 
| #    BYTE        PosNum;        //Íæ¼Òµã»÷µÄ½±ÀøÎ»ÖñàºÅ£¬´Ó1¿ªÊ¼  | 
| #};  | 
| def OnActXianXiaMJLottery(index, clientData, tick):  | 
|     curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)  | 
|     actNum = clientData.ActNum  | 
|     reqPosNum = clientData.PosNum  | 
|       | 
|     GameWorld.DebugLog("ÏÉÏ»ÃØ¾³»î¶¯³é½±: actNum=%s,reqPosNum=%s" % (actNum, reqPosNum))  | 
|       | 
|     if reqPosNum <= 0:  | 
|         return  | 
|       | 
|     actInfo = GameWorld.GetActInfo(ShareDefine.OperationActionName_XianXiaMJ, actNum)  | 
|     if not actInfo.get(ShareDefine.ActKey_State):  | 
|         GameWorld.DebugLog("    ·Ç»î¶¯ÖÐ!")  | 
|         return  | 
|       | 
|     cfgID = actInfo.get(ShareDefine.ActKey_CfgID)  | 
|     ipyData = IpyGameDataPY.GetIpyGameData("ActXianXiaMJ", cfgID)  | 
|     if not ipyData:  | 
|         return  | 
|       | 
|     templateID = ipyData.GetTemplateID()  | 
|     if not templateID:  | 
|         return  | 
|       | 
|     actWorldLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_XianXiaMJWorldLV % actNum)  | 
|     awardIpyDataList = IpyGameDataPY.GetIpyGameDataList("ActXianXiaMJAward", templateID)  | 
|     if not awardIpyDataList:  | 
|         return  | 
|       | 
|     costMoneyType, costMoneyValue = ipyData.GetUseMoneyInfo()  | 
|     if not PlayerControl.HaveMoney(curPlayer, costMoneyType, costMoneyValue):  | 
|         GameWorld.DebugLog("    »õ±Ò²»×㣬ÎÞ·¨³é½±! costMoneyType=%s,costMoneyValue(%s) > curMoneyValue(%s)"   | 
|                            % (costMoneyType, costMoneyValue, PlayerControl.GetMoney(curPlayer, costMoneyType)))  | 
|         return  | 
|       | 
|     layerInfoValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_XianXiaMJAwardLayerInfo % actNum)  | 
|     playCount, layerNum = layerInfoValue / 100, layerInfoValue % 100  | 
|       | 
|     posNumMax = 0  | 
|     randLibItemDict = {}  | 
|     for awardIpyData in awardIpyDataList:  | 
|         libType = awardIpyData.GetAwardLibType()  | 
|         libItemCount = awardIpyData.GetAwardItemCount()  | 
|         unlockLimitTimes = awardIpyData.GetUnlockAwardLimitTimes()  | 
|         libWeight = awardIpyData.GetAwardLibWeight()  | 
|         posNumMax += libItemCount  | 
|           | 
|         if libType == Def_SuperLibType:  | 
|             for num in xrange(libItemCount):  | 
|                 itemInfoValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_XianXiaMJAwardItemInfo % (actNum, libType, num))  | 
|                 if not itemInfoValue:  | 
|                     GameWorld.DebugLog("    Î´Ñ¡Ôñ´ó½±£¡ÎÞ·¨³é½±! libType=%s,num=%s,itemInfoValue=%s" % (libType, num, itemInfoValue))           | 
|                     return  | 
|                   | 
|         if unlockLimitTimes and playCount < unlockLimitTimes:  | 
|             GameWorld.DebugLog("    ¸Ã¿âµ±Ç°³é½±´ÎÊýÎÞ·¨½âËø! libType=%s,playCount(%s) < unlockLimitTimes(%s)" % (libType, playCount, unlockLimitTimes))  | 
|             continue  | 
|           | 
|         awardTimesTotalInfo = awardIpyData.GetItemAwardTimesTotalInfo()  | 
|         libItemDict = __GetXianXiaMJAwardLibItem(awardIpyData.GetLibItemInfo(), actWorldLV)  | 
|         canRandItemList = []  | 
|         for num in xrange(libItemCount):  | 
|             itemInfoValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_XianXiaMJAwardItemInfo % (actNum, libType, num))  | 
|             if not itemInfoValue:              | 
|                 return  | 
|               | 
|             itemID, posNum = itemInfoValue / 100, itemInfoValue % 100  | 
|             if itemID not in libItemDict:  | 
|                 continue  | 
|               | 
|             if posNum:  | 
|                 GameWorld.DebugLog("    ¸Ã½±Æ·Òѱ»³éÖÐ! libType=%s,itemID=%s,posNum=%s" % (libType, itemID, posNum))  | 
|                 if posNum == reqPosNum:  | 
|                     GameWorld.ErrLog("    ¸ÃλÖÃÒѾÓг齱½á¹û£¬ÎÞ·¨Öظ´Ñ¡Ôñ³é½±! libType=%s,num=%s,itemInfoValue=%s,posNum=%s"   | 
|                                      % (libType, num, itemInfoValue, posNum))                  | 
|                     return                  | 
|                 continue  | 
|               | 
|             itemCount, weight = libItemDict[itemID]  | 
|             isAddTimes = (itemID in awardTimesTotalInfo)  | 
|             canRandItemList.append([weight, itemID, itemCount, num, isAddTimes])  | 
|               | 
|         if canRandItemList:  | 
|             randLibItemDict[libType] = [libWeight, libType, canRandItemList]  | 
|             GameWorld.DebugLog("    ¸Ã¿âÓлú»á³éµ½ÎïÆ·: libType=%s,libWeight=%s,canRandItemList=%s" % (libType, libWeight, canRandItemList))  | 
|         else:  | 
|             GameWorld.DebugLog("    ¸Ã¿âÎïÆ·ÒÑÈ«±»³éÍê: libType=%s,libWeight=%s,canRandItemList=%s" % (libType, libWeight, canRandItemList))  | 
|               | 
|     if reqPosNum > posNumMax:  | 
|         GameWorld.DebugLog("    ÇëÇóλÖÃÒì³££¬ÎÞ·¨³é½±! reqPosNum(%s) > posNumMax(%s)" % (reqPosNum, posNumMax))  | 
|         return  | 
|       | 
|     if not randLibItemDict:  | 
|         GameWorld.DebugLog("    Ã»Óпɳ齱µÄ½±Æ·ÁË£¬ÎÞ·¨³é½±!")  | 
|         return  | 
|       | 
|     randLibInfo = GameWorld.GetResultByWeightList(randLibItemDict.values())  | 
|     if not randLibInfo:  | 
|         return  | 
|     libType, canRandItemList = randLibInfo  | 
|     randItemInfo = GameWorld.GetResultByWeightList(canRandItemList)  | 
|     if not randItemInfo:  | 
|         return  | 
|     itemID, itemCount, num, isAddTimes = randItemInfo  | 
|       | 
|     # ¿Û³ý³é½±ÏûºÄ»·±£Öµ  | 
|     PlayerControl.PayMoney(curPlayer, costMoneyType, costMoneyValue, "ActXianXiaMJ")  | 
|       | 
|     # ¸üÐÂÒѳéÖÐÖµ  | 
|     updItemInfoValue = itemID * 100 + reqPosNum  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_XianXiaMJAwardItemInfo % (actNum, libType, num), updItemInfoValue)  | 
|       | 
|     totalTimesNow = 0  | 
|     if isAddTimes:  | 
|         totalTimesNow = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_XianXiaMJAwardItemTimes % (actNum, libType, itemID)) + 1  | 
|         PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_XianXiaMJAwardItemTimes % (actNum, libType, itemID), totalTimesNow)  | 
|           | 
|     playCount += 1  | 
|     layerInfoValue = playCount * 100 + layerNum  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_XianXiaMJAwardLayerInfo % actNum, layerInfoValue)  | 
|       | 
|     GameWorld.DebugLog("    ³éÖÐÎïÆ·: layerNum=%s,libType=%s,itemID=%s,itemCount=%s,num=%s,reqPosNum=%s,updItemInfoValue=%s,totalTimesNow=%s,playCount=%s(%s)"   | 
|                        % (layerNum, libType, itemID, itemCount, num, reqPosNum, updItemInfoValue, totalTimesNow, playCount, layerInfoValue))  | 
|       | 
|     # ¸øÎïÆ·  | 
|     isAuctionItem = 0  | 
|     itemList = [[itemID, itemCount, isAuctionItem]]  | 
|     ItemControler.GivePlayerItemOrMail(curPlayer, itemList, event=["tagActXianXiaMJLottery", False, {}])  | 
|       | 
|     # ¹ã²¥  | 
|     if libType == Def_SuperLibType:  | 
|         PlayerControl.WorldNotify(0, "XianXiaMJ%s" % actNum, [curPlayer.GetPlayerName(), itemID, itemCount])  | 
|           | 
|     # Í¨Öª³é½±½á¹û  | 
|     clientPack = ChPyNetSendPack.tagMCActXianXiaMJAwardItemResult()  | 
|     clientPack.ActNum = actNum  | 
|     clientPack.ItemLibType = libType  | 
|     clientPack.ItemID = itemID  | 
|     clientPack.ItemCount = itemCount  | 
|     clientPack.PosNum = reqPosNum  | 
|     clientPack.TotalTimesNow = totalTimesNow  | 
|     NetPackCommon.SendFakePack(curPlayer, clientPack)  | 
|     return  | 
|   | 
| def Sync_XianXiaMJActionInfo(curPlayer, actNum):  | 
|     ## Í¨Öª»î¶¯ÐÅÏ¢  | 
|       | 
|     actInfo = GameWorld.GetActInfo(ShareDefine.OperationActionName_XianXiaMJ, actNum)  | 
|     if not actInfo.get(ShareDefine.ActKey_State):  | 
|         return  | 
|       | 
|     cfgID = actInfo.get(ShareDefine.ActKey_CfgID)  | 
|     ipyData = IpyGameDataPY.GetIpyGameData("ActXianXiaMJ", cfgID)  | 
|     if not ipyData:  | 
|         return  | 
|       | 
|     templateID = ipyData.GetTemplateID()  | 
|     if not templateID:  | 
|         return  | 
|     costMoneyType, costMoneyValue = ipyData.GetUseMoneyInfo()  | 
|       | 
|     actWorldLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_XianXiaMJWorldLV % actNum)  | 
|     startDateStr, endDateStr = GameWorld.GetOperationActionDateStr(ipyData)  | 
|       | 
|     layerInfoValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_XianXiaMJAwardLayerInfo % actNum)  | 
|     layerNum = layerInfoValue % 100  | 
|       | 
|     clientPack = ChPyNetSendPack.tagMCActXianXiaMJInfo()  | 
|     clientPack.ActNum = actNum  | 
|     clientPack.StartDate = startDateStr  | 
|     clientPack.EndtDate = endDateStr  | 
|     clientPack.LimitLV = ipyData.GetLVLimit()  | 
|     clientPack.ResetType = ipyData.GetResetType()  | 
|     clientPack.MoneyType = costMoneyType  | 
|     clientPack.MoneyValue = costMoneyValue  | 
|     clientPack.LayerNum = layerNum  | 
|     clientPack.AwardItemList = [] # ½±³ØÎïÆ·ÁÐ±í  | 
|     awardIpyDataList = IpyGameDataPY.GetIpyGameDataList("ActXianXiaMJAward", templateID)  | 
|     if awardIpyDataList:  | 
|         for awardIpyData in awardIpyDataList:  | 
|             libType = awardIpyData.GetAwardLibType()  | 
|             libItemCount = awardIpyData.GetAwardItemCount()  | 
|             libItemDict = __GetXianXiaMJAwardLibItem(awardIpyData.GetLibItemInfo(), actWorldLV)  | 
|             layerLimitInfo = awardIpyData.GetItemLayerLimitInfo()  | 
|             awardTimesTotalInfo = awardIpyData.GetItemAwardTimesTotalInfo()  | 
|               | 
|             # ½±³ØÎïÆ·ÁÐ±í£¬ÒÑÉú³ÉµÄ£¬°üº¬ÒÑÑ¡ÔñµÄ´ó½±ÎïÆ·  | 
|             for num in xrange(libItemCount):  | 
|                 itemInfoValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_XianXiaMJAwardItemInfo % (actNum, libType, num))  | 
|                 if not itemInfoValue:  | 
|                     break  | 
|                 itemID, posNum = itemInfoValue / 100, itemInfoValue % 100  | 
|                 if itemID not in libItemDict:  | 
|                     continue  | 
|                 libItemInfo = libItemDict[itemID]  | 
|                   | 
|                 awardItem = ChPyNetSendPack.tagMCActXianXiaMJAwardItem()  | 
|                 awardItem.ItemLibType = libType  | 
|                 awardItem.ItemID = itemID  | 
|                 awardItem.ItemCount = libItemInfo[0]  | 
|                 awardItem.PosNum = posNum  | 
|                 awardItem.TotalTimesMax = awardTimesTotalInfo.get(itemID, 0)  | 
|                 awardItem.TotalTimesNow = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_XianXiaMJAwardItemTimes % (actNum, libType, itemID))  | 
|                 awardItem.LayerLimit = layerLimitInfo.get(itemID, 0)  | 
|                 clientPack.AwardItemList.append(awardItem)  | 
|                   | 
|             # ´ó½±ÎïÆ·´ýÑ¡Ôñ¿â£¬È«²¿Í¬²½  | 
|             if libType == Def_SuperLibType:  | 
|                 for itemID, libItemInfo in libItemDict.items():  | 
|                     awardItem = ChPyNetSendPack.tagMCActXianXiaMJAwardItem()  | 
|                     awardItem.ItemLibType = libType  | 
|                     awardItem.ItemID = itemID  | 
|                     awardItem.ItemCount = libItemInfo[0]  | 
|                     awardItem.TotalTimesMax = awardTimesTotalInfo.get(itemID, 0)  | 
|                     awardItem.TotalTimesNow = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_XianXiaMJAwardItemTimes % (actNum, libType, itemID))  | 
|                     awardItem.LayerLimit = layerLimitInfo.get(itemID, 0)  | 
|                     clientPack.SuperItemList.append(awardItem)  | 
|                 clientPack.SuperItemCount = len(clientPack.SuperItemList)  | 
|                 clientPack.SuperItemCanChooseCount = libItemCount  | 
|                   | 
|     clientPack.AwardItemCount = len(clientPack.AwardItemList)  | 
|     NetPackCommon.SendFakePack(curPlayer, clientPack)  | 
|     return  | 
|   | 
| def __GetXianXiaMJAwardLibItem(libItemInfo, actWorldLV):  | 
|     ## »ñÈ¡½±Àø¿âÎïÆ·ÐÅÏ¢×ֵ䣬֧³Ö°´ÊÀ½çµÈ¼¶·¶Î§ÅäÖõĸñʽ  | 
|     keyList = libItemInfo.keys()  | 
|     if not keyList:  | 
|         return {}  | 
|     if isinstance(keyList[0], tuple) and len(keyList[0]) == 2:  | 
|         return GameWorld.GetDictValueByRangeKey(libItemInfo, actWorldLV, {})  | 
|     return libItemInfo  | 
|   |