| #!/usr/bin/python  | 
| # -*- coding: GBK -*-  | 
| #-------------------------------------------------------------------------------  | 
| #  | 
| ##@package Player.PlayerFeastTravel  | 
| #  | 
| # @todo:½ÚÈÕÓÎÀú  | 
| # @author hxp  | 
| # @date 2021-02-01  | 
| # @version 1.0  | 
| #  | 
| # ÏêϸÃèÊö: ½ÚÈÕÓÎÀú  | 
| #  | 
| #-------------------------------------------------------------------------------  | 
| #"""Version = 2021-02-01 15:00"""  | 
| #-------------------------------------------------------------------------------  | 
|   | 
| import PyGameData  | 
| import ShareDefine  | 
| import PlayerControl  | 
| import IpyGameDataPY  | 
| import ItemControler  | 
| import ChPyNetSendPack  | 
| import IPY_GameWorld  | 
| import NetPackCommon  | 
| import GameWorld  | 
| import ChConfig  | 
|   | 
| def OnPlayerLogin(curPlayer):  | 
|     isReset = __CheckPlayerFeastTravelAction(curPlayer)  | 
|     if not isReset:  | 
|         actInfo = PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_FeastTravel, {})  | 
|         # »î¶¯ÖÐͬ²½»î¶¯ÐÅÏ¢  | 
|         if actInfo.get(ShareDefine.ActKey_State):  | 
|             Sync_FeastTravelActionInfo(curPlayer)  | 
|             Sync_FeastTravelPlayerInfo(curPlayer)  | 
|     return  | 
|   | 
| def RefreshFeastTravelActionInfo():  | 
|     ## ÊÕµ½GameServerͬ²½µÄ»î¶¯ÐÅÏ¢£¬Ë¢Ð»ÐÅÏ¢  | 
|     playerManager = GameWorld.GetPlayerManager()  | 
|     for index in xrange(playerManager.GetPlayerCount()):  | 
|         curPlayer = playerManager.GetPlayerByIndex(index)  | 
|         if not GameWorld.IsNormalPlayer(curPlayer):  | 
|             continue  | 
|         __CheckPlayerFeastTravelAction(curPlayer)  | 
|     return  | 
|   | 
| def __CheckPlayerFeastTravelAction(curPlayer):  | 
|     ## ¼ì²éÍæ¼Ò»î¶¯ÐÅÏ¢  | 
|       | 
|     playerID = curPlayer.GetPlayerID()  | 
|       | 
|     actInfo = PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_FeastTravel, {})  | 
|     actID = actInfo.get(ShareDefine.ActKey_ID, 0)  | 
|     state = actInfo.get(ShareDefine.ActKey_State, 0)  | 
|       | 
|     playerActID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FeastTravelID) # Íæ¼ÒÉíÉϵĻID  | 
|     # »î¶¯ID ÏàͬµÄ»°²»´¦Àí  | 
|     if actID == playerActID:  | 
|         GameWorld.DebugLog("½ÚÈÕÓÎÀú»î¶¯ID²»±ä£¬²»´¦Àí£¡", curPlayer.GetPlayerID())  | 
|         return  | 
|     GameWorld.DebugLog("½ÚÈÕÓÎÀú»î¶¯ÖØÖÃ! actID=%s,playerActID=%s,state=%s" % (actID, playerActID, state), playerID)  | 
|       | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FeastTravelID, actID)  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FeastTravelPoint, 0)  | 
|       | 
|     if not state:  | 
|         return  | 
|       | 
|     templateID = __GetTravelTemplateID()  | 
|       | 
|     ipyMgr = IpyGameDataPY.IPY_Data()  | 
|     # ÖØÖÃÓÎÀúÈÎÎñÏà¹Ø  | 
|     for index in xrange(ipyMgr.GetActFeastTravelTaskCount()):  | 
|         taskIpyData = ipyMgr.GetActFeastTravelTaskByIndex(index)  | 
|         taskID = taskIpyData.GetTraveTasklD()  | 
|         PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FeastTravelValue % taskID, 0)  | 
|         PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FeastTravelCount % taskID, 0)  | 
|           | 
|     # ÖØÖÃÓÎÀú½±Àø  | 
|     for index in xrange(ipyMgr.GetActFeastTravelAwardCount()):  | 
|         awardIpyData = ipyMgr.GetActFeastTravelAwardByIndex(index)  | 
|         if templateID != awardIpyData.GetTemplatelD():  | 
|             continue  | 
|         recordIndex = awardIpyData.GetRecordIndex()  | 
|         PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FeastTravelAwardCount % recordIndex, 0)  | 
|           | 
|     Sync_FeastTravelActionInfo(curPlayer)  | 
|     Sync_FeastTravelPlayerInfo(curPlayer)  | 
|     return True  | 
|   | 
| def __GetTravelTemplateID():  | 
|     actInfo = PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_FeastTravel, {})  | 
|     if not actInfo:  | 
|         return  | 
|       | 
|     if not actInfo.get(ShareDefine.ActKey_State):  | 
|         return  | 
|       | 
|     cfgID = actInfo.get(ShareDefine.ActKey_CfgID)  | 
|     ipyData = IpyGameDataPY.GetIpyGameData("ActFeastTravel", cfgID)  | 
|     if not ipyData:  | 
|         return  | 
|       | 
|     worldLV = actInfo.get(ShareDefine.ActKey_WorldLV)  | 
|     templateID = GameWorld.GetDictValueByRangeKey(ipyData.GetTemplateIDInfo(), worldLV, 0)  | 
|     return templateID  | 
|   | 
| def AddFeastTravelTaskValue(curPlayer, taskID, addValue=1):  | 
|     ## Ôö¼ÓÓÎÀúÈÎÎñÍê³É½ø¶È  | 
|     actInfo = PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_FeastTravel, {})  | 
|     if not actInfo:  | 
|         return  | 
|     if not actInfo.get(ShareDefine.ActKey_State):  | 
|         return  | 
|     ipyData = IpyGameDataPY.GetIpyGameData("ActFeastTravelTask", taskID)  | 
|     if not ipyData:  | 
|         return  | 
|     maxFinishCount = ipyData.GetFinishTimeMax()  | 
|     curFinishCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FeastTravelCount % taskID)  | 
|     if maxFinishCount and curFinishCount >= maxFinishCount:  | 
|         GameWorld.DebugLog("¸ÃÓÎÀúÈÎÎñÒÑ´ïµ½×î´óÍê³É´ÎÊý!taskID=%s,curFinishCount=%s" % (taskID, curFinishCount))  | 
|         return  | 
|     curValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FeastTravelValue % taskID)          | 
|     updValue = curValue + addValue  | 
|     GameWorld.DebugLog("Ôö¼ÓÓÎÀú½ø¶È: taskID=%s,curValue=%s,addValue=%s,updValue=%s" % (taskID, curValue, addValue, updValue))  | 
|       | 
|     if maxFinishCount:  | 
|         maxValue = ipyData.GetFinishNeedValue() * maxFinishCount  | 
|         if updValue > maxValue:  | 
|             updValue = maxValue  | 
|             GameWorld.DebugLog("    ÐÞÕý½ø¶ÈÖµ²»³¬¹ý×î´ó¿ÉÍê³É´ÎÊýµÄ×ܽø¶ÈÖµ! maxFinishCount=%s,maxValue=%s,updValue=%s"   | 
|                                % (maxFinishCount, maxValue, updValue))  | 
|               | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FeastTravelValue % taskID, updValue)  | 
|     updFinishCount = updValue / ipyData.GetFinishNeedValue()  | 
|     GameWorld.DebugLog("    curFinishCount=%s,updFinishCount=%s" % (curFinishCount, updFinishCount))  | 
|     # Ôö¼ÓÍê³É´ÎÊý  | 
|     if updFinishCount > curFinishCount:  | 
|         PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FeastTravelCount % taskID, updFinishCount)  | 
|         addFinishCount = updFinishCount - curFinishCount  | 
|         addTravelPointTotal = addFinishCount * ipyData.GetAddTravelPoint()  | 
|           | 
|         curTravelPoint = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FeastTravelPoint)  | 
|         updTravelPoint = curTravelPoint + addTravelPointTotal  | 
|         PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FeastTravelPoint, updTravelPoint)  | 
|         GameWorld.DebugLog("    Íê³ÉÓÎÀú: addFinishCount=%s,addTravelPointTotal=%s,curTravelPoint=%s,updTravelPoint=%s"   | 
|                            % (addFinishCount, addTravelPointTotal, curTravelPoint, updTravelPoint))  | 
|           | 
|     Sync_FeastTravelPlayerInfo(curPlayer, taskID, -1) # ²»Í¨Öª½±Àø  | 
|     return True  | 
|   | 
| def GetFeastTravelAward(curPlayer, index):  | 
|     ## ½ÚÈÕÓÎÀúÁì½±  | 
|       | 
|     templateID = __GetTravelTemplateID()  | 
|     if not templateID:  | 
|         return  | 
|       | 
|     ipyDataList = IpyGameDataPY.GetIpyGameDataList("ActFeastTravelAward", templateID)  | 
|     if not ipyDataList:  | 
|         return  | 
|       | 
|     findIpyData = None  | 
|     for ipyData in ipyDataList:  | 
|         if index == ipyData.GetRecordIndex():  | 
|             findIpyData = ipyData  | 
|             break  | 
|           | 
|     if not findIpyData:  | 
|         return  | 
|       | 
|     getCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FeastTravelAwardCount % index)  | 
|     getCountMax = findIpyData.GetAwardCountMax()  | 
|     if getCountMax and getCount >= getCountMax:  | 
|         GameWorld.DebugLog("    ½ÚÈÕÓÎÀúÁì½±ÒÑ´ï×î´óÁìÈ¡´ÎÊý! templateID=%s,index=%s,getCount=%s >= getCountMax=%s"   | 
|                            % (templateID, index, getCount, getCountMax))  | 
|         return  | 
|       | 
|     curPoint = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FeastTravelPoint)  | 
|     singleNeedPoint = findIpyData.GetNeedTravelPoint()  | 
|     canUsePoint = curPoint - getCount * singleNeedPoint  | 
|     if canUsePoint < singleNeedPoint:  | 
|         GameWorld.DebugLog("    ½ÚÈÕÓÎÀúÁì½±ÓÎÀúÖµ²»×ã! templateID=%s,index=%s,curPoint=%s,getCount=%s,canUsePoint=%s < singleNeedPoint=%s"   | 
|                            % (templateID, index, curPoint, getCount, canUsePoint, singleNeedPoint))  | 
|         return  | 
|       | 
|     awardList = findIpyData.GetTravelAwardInfo()  | 
|     if not awardList:  | 
|         return  | 
|       | 
|     if not ItemControler.CheckPackSpaceEnough(curPlayer, awardList):  | 
|         return  | 
|       | 
|     updGetCount = getCount + 1  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FeastTravelAwardCount % index, updGetCount)  | 
|       | 
|     GameWorld.DebugLog("    ½ÚÈÕÓÎÀúÁì½±! templateID=%s,index=%s,curPoint=%s,getCount=%s,canUsePoint=%s,singleNeedPoint=%s,updGetCount=%s"   | 
|                        % (templateID, index, curPoint, getCount, canUsePoint, singleNeedPoint, updGetCount))  | 
|       | 
|     for itemID, itemCnt, isAuctionItem in awardList:  | 
|         ItemControler.GivePlayerItem(curPlayer, itemID, itemCnt, isAuctionItem, [IPY_GameWorld.rptItem], event=["FeastTravel", False, {}])  | 
|           | 
|     Sync_FeastTravelPlayerInfo(curPlayer, -1, index) # ²»Í¨ÖªÈÎÎñ  | 
|     return  | 
|   | 
| def Sync_FeastTravelPlayerInfo(curPlayer, taskID=None, awardIndex=None):  | 
|     ## Í¨Öª»î¶¯Íæ¼ÒÐÅÏ¢  | 
|     # @param taskID: None-֪ͨȫ²¿£»>=0-µ¥¸ö֪ͨ£»-1-²»Í¨Öª  | 
|       | 
|     syncTaskIDList = []  | 
|     if taskID == None:  | 
|         ipyMgr = IpyGameDataPY.IPY_Data()  | 
|         for index in xrange(ipyMgr.GetActFeastTravelTaskCount()):  | 
|             taskIpyData = ipyMgr.GetActFeastTravelTaskByIndex(index)  | 
|             syncTaskIDList.append(taskIpyData.GetTraveTasklD())  | 
|     elif taskID >= 0:  | 
|         syncTaskIDList = [taskID]  | 
|           | 
|     syncAwardIndexList = []  | 
|     if awardIndex == None:  | 
|         templateID = __GetTravelTemplateID()  | 
|         if templateID:  | 
|             awardIpyDataList = IpyGameDataPY.GetIpyGameDataList("ActFeastTravelAward", templateID)  | 
|             if awardIpyDataList:  | 
|                 syncAwardIndexList = [awardIpyData.GetRecordIndex() for awardIpyData in awardIpyDataList]  | 
|     elif awardIndex >= 0:  | 
|         syncAwardIndexList = [awardIndex]  | 
|           | 
|     playerPack = ChPyNetSendPack.tagMCFeastTravelPlayerInfo()  | 
|     playerPack.TravelPoint = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FeastTravelPoint)  | 
|     playerPack.TravelPlayerTaskList = []  | 
|     for taskID in syncTaskIDList:  | 
|         taskInfo = ChPyNetSendPack.tagMCFeastTravelPlayerTask()  | 
|         taskInfo.TravelTaskID = taskID  | 
|         taskInfo.TravelValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FeastTravelValue % taskID)  | 
|         taskInfo.FinishCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FeastTravelCount % taskID)  | 
|         playerPack.TravelPlayerTaskList.append(taskInfo)  | 
|     playerPack.TravelPlayerTaskCount = len(playerPack.TravelPlayerTaskList)  | 
|       | 
|     playerPack.TravelPlayerAwardList = []  | 
|     for awardIndex in syncAwardIndexList:  | 
|         awardInfo = ChPyNetSendPack.tagMCFeastTravelPlayerAward()  | 
|         awardInfo.AwardIndex = awardIndex  | 
|         awardInfo.GetAwardCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FeastTravelAwardCount % awardIndex)  | 
|         playerPack.TravelPlayerAwardList.append(awardInfo)  | 
|     playerPack.TravelPlayerAwardCount = len(playerPack.TravelPlayerAwardList)  | 
|       | 
|     NetPackCommon.SendFakePack(curPlayer, playerPack)  | 
|     return  | 
|   | 
| def Sync_FeastTravelActionInfo(curPlayer):  | 
|     ## Í¨Öª»î¶¯ÐÅÏ¢  | 
|     actInfo = PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_FeastTravel, {})  | 
|     if not actInfo:  | 
|         return  | 
|       | 
|     if not actInfo.get(ShareDefine.ActKey_State):  | 
|         return  | 
|       | 
|     cfgID = actInfo.get(ShareDefine.ActKey_CfgID)  | 
|     ipyData = IpyGameDataPY.GetIpyGameData("ActFeastTravel", cfgID)  | 
|     if not ipyData:  | 
|         return  | 
|       | 
|     worldLV = actInfo.get(ShareDefine.ActKey_WorldLV)  | 
|     templateID = GameWorld.GetDictValueByRangeKey(ipyData.GetTemplateIDInfo(), worldLV, 0)  | 
|     if not templateID:  | 
|         return  | 
|       | 
|     startDateStr, endDateStr = GameWorld.GetOperationActionDateStr(ipyData)  | 
|     actPack = ChPyNetSendPack.tagMCFeastTravelInfo()  | 
|     actPack.Clear()  | 
|     actPack.StartDate = startDateStr  | 
|     actPack.EndtDate = endDateStr  | 
|     actPack.LimitLV = ipyData.GetLVLimit()  | 
|     actPack.ResetType = ipyData.GetResetType()  | 
|       | 
|     actPack.TravelTaskList = []  | 
|     ipyMgr = IpyGameDataPY.IPY_Data()  | 
|     for index in xrange(ipyMgr.GetActFeastTravelTaskCount()):  | 
|         taskIpyData = ipyMgr.GetActFeastTravelTaskByIndex(index)  | 
|         taskInfo = ChPyNetSendPack.tagMCFeastTravelTask()  | 
|         taskInfo.TravelTaskID = taskIpyData.GetTraveTasklD()  | 
|         taskInfo.FinishNeedValue = taskIpyData.GetFinishNeedValue()  | 
|         taskInfo.FinishTimeMax = taskIpyData.GetFinishTimeMax()  | 
|         taskInfo.AddTravelPoint = taskIpyData.GetAddTravelPoint()  | 
|         actPack.TravelTaskList.append(taskInfo)  | 
|     actPack.TravelTaskCount = len(actPack.TravelTaskList)  | 
|       | 
|     awardIpyDataList = IpyGameDataPY.GetIpyGameDataList("ActFeastTravelAward", templateID)  | 
|     actPack.TravelAwardList = []  | 
|     for awardIpyData in awardIpyDataList:  | 
|         awardInfo = ChPyNetSendPack.tagMCFeastTravelAward()  | 
|         awardInfo.AwardIndex = awardIpyData.GetRecordIndex()  | 
|         awardInfo.NeedTravelPoint = awardIpyData.GetNeedTravelPoint()  | 
|         awardInfo.AwardCountMax = awardIpyData.GetAwardCountMax()  | 
|         awardInfo.AwardItemList = []  | 
|         for itemID, itemCount, isAuctionItem in awardIpyData.GetTravelAwardInfo():  | 
|             itemInfo = ChPyNetSendPack.tagMCFeastTravelAwardItem()  | 
|             itemInfo.ItemID = itemID  | 
|             itemInfo.ItemCount = itemCount  | 
|             itemInfo.IsBind = isAuctionItem  | 
|             awardInfo.AwardItemList.append(itemInfo)  | 
|         awardInfo.AwardItemCount = len(awardInfo.AwardItemList)  | 
|         actPack.TravelAwardList.append(awardInfo)  | 
|     actPack.TravelAwardCount = len(actPack.TravelAwardList)  | 
|       | 
|     NetPackCommon.SendFakePack(curPlayer, actPack)  | 
|     return  | 
|   |