| #!/usr/bin/python  | 
| # -*- coding: GBK -*-  | 
| #  | 
| #  | 
| ##@package PlayerFB.py  | 
| #  | 
| # @todo:Íæ¼Ò¸±±¾  | 
| #  | 
| # @author hxp  | 
| # @date 2013-08-20  | 
| # @version 2.0  | 
| # @note:  | 
| # @change: "2014-08-01 00:30" hxp Ôö¼ÓÇå³ý¸±±¾Àäȴʱ¼äÂß¼  | 
| # @change: "2014-12-08 17:00" hxp Ôö¼ÓÇ帱±¾CD×êʯÏû·ÑÁ÷Ïò  | 
| # @change: "2015-02-10 22:30" hxp Ôö¼Ó×êʯÏûºÄÀàÐÍʼþ»ã±¨  | 
| # @change: "2015-06-29 18:00" xdh Ôö¼ÓÍæ¼Ò¸±±¾·ÅÆÈë¿Ú  | 
| # @change: "2016-02-30 17:00" hxp ÁìÖ÷°ÔÒµ¡¢¶ñħÊÔÁ¶  | 
| # @change: "2016-03-20 15:30" hxp ¸±±¾¶à±¶½±Àø£»¹«¹²CD¸±±¾É¨µ´  | 
| # @change: "2016-04-19 17:30" xdh ¸±±¾É¨µ´Ëã»îÔ¾¶È  | 
| # @change: "2016-04-26 15:30" hxp ¶à±¶½±Àø°Ù·Ö±È¸ÄΪ½±ÀøµÈ¼¶£» É¨µ´Ôö¼ÓÇëÇóCD  | 
| # @change: "2016-08-15 11:20" xdh ¸±±¾É¨µ´ÏûºÄµÀ¾ß  | 
| # @change: "2016-12-02 11:00" xdh ¸±±¾É¨µ´Ôö¼ÓÈËÎïµÈ¼¶ÅÐ¶Ï  | 
| #------------------------------------------------------------------------------   | 
| #"""Version = 2016-12-02 11:00"""  | 
| #------------------------------------------------------------------------------   | 
| import ReadChConfig  | 
| import IPY_GameWorld  | 
| import PlayerControl  | 
| import GameWorld  | 
| import FBCommon  | 
| import ChConfig  | 
| import FBLogic  | 
| import ChPyNetSendPack  | 
| import NetPackCommon  | 
| import PlayerSuccess  | 
| import ItemCommon  | 
| import IpyGameDataPY  | 
| import ShareDefine  | 
| import GameFuncComm  | 
| import FBHelpBattle  | 
| import SkillShell  | 
| import PyGameData  | 
| import PetControl  | 
| import NPCCommon  | 
|   | 
| import time  | 
| import math  | 
| #---------------------------------------------------------------------  | 
| def OnLogin(curPlayer):  | 
|     NotifyBuyFBBuffInfo(curPlayer)  | 
|     return  | 
|   | 
| ## Íæ¼Ò¸±±¾ÐÐΪ·â°ü A5 08  | 
| #  @param playerIndex Íæ¼ÒË÷Òý    | 
| #  @param clientData ¿Í»§¶Ë·â°ü    | 
| #  @param tick Ê±¼ä  | 
| #  @return None  | 
| def OnDoFBAction(playerIndex, clientData, tick):  | 
|     curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(playerIndex)  | 
|     actionType = clientData.ActionType # ÐÐΪÀàÐÍ  | 
|     actionInfo = clientData.ActionInfo # ÐÐΪÐÅÏ¢  | 
|     FBLogic.DoFBAction(curPlayer, actionType, actionInfo, tick)  | 
|     return  | 
|   | 
| ## A2 10 Çå³ý¸±±¾CD#tagCMClearFBCD  | 
| #  @param playerIndex Íæ¼ÒË÷Òý    | 
| #  @param clientData ¿Í»§¶Ë·â°ü    | 
| #  @param tick Ê±¼ä  | 
| #  @return None  | 
| def OnClearFBCD(playerIndex, clientData, tick):  | 
|     curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(playerIndex)  | 
|     mapID = clientData.MapID # mapID  | 
|     GameWorld.DebugLog("OnClearFBCD mapID=%s" % mapID)  | 
|     if not mapID:  | 
|         return  | 
|       | 
|     enterCDTick = FBCommon.GetFBEnterCD(curPlayer, mapID)  | 
|     if enterCDTick <= 0:  | 
|         GameWorld.DebugLog("    CDʱ¼äÒѹý£¬²»ÐèÒªÇå³ý£¬ cdTick=%s" % enterCDTick)  | 
|         return  | 
|     clearEnterCDDict = IpyGameDataPY.GetFuncEvalCfg('FBEnterCD', 2)  | 
|     if mapID not in clearEnterCDDict:  | 
|         return  | 
|     costMoney = clearEnterCDDict[mapID]  | 
|     costMoneyList = PlayerControl.HaveMoneyEx(curPlayer, ShareDefine.TYPE_Price_Gold_Paper_Money, costMoney)  | 
|     if not costMoneyList:  | 
|         return  | 
|     second = enterCDTick # ²ÎÊýÃë  | 
|     # ¿Û³ýÏûºÄ  | 
|     infoDict = {"MapID":mapID, "CDSecond":second}  | 
|     for moneyType, moneyCnt in costMoneyList:  | 
|         if not PlayerControl.PayMoney(curPlayer, moneyType, moneyCnt, ChConfig.Def_Cost_ClearFBCD, infoDict):  | 
|             return  | 
|      | 
|   | 
|     GameWorld.DebugLog("   mapID=%s Çå³ý¸±±¾CD second=%s,costMoneyList=%s"   | 
|                          % (mapID, second, costMoneyList), curPlayer.GetPlayerID())  | 
|       | 
|     FBCommon.SetFBPDictValue(curPlayer, ChConfig.Def_PDict_LastEnterFBTick % mapID, 0)  | 
|     FBCommon.SyncFBEnterTick(curPlayer)  | 
|     return  | 
|   | 
| #---·â°ü¿ªÊ¼É¨µ´-------------------------------------  | 
|   | 
| (  | 
| PCDFB_MapIDList, # ¸±±¾µØÍ¼IDÁÐ±í  | 
| PCDFB_NeedTime, # É¨µ´Ê±¼ä, Ãë  | 
| PCDFB_FinishTimeGold, # Á¢¼´Íê³ÉÏûºÄ×êʯ¹«Ê½  | 
| ) = range(3)  | 
|   | 
|   | 
| ## ÅжÏÊÇ·ñµ±Ç°¹«¹²CD¸±±¾É¨µ´ÖÐ  | 
| def IsCurPubCDFBSweeping(curPlayer, mapID):  | 
|     sweepCfg = GetPubCDFBSweepCfg(curPlayer, mapID)  | 
|     if not sweepCfg:  | 
|         return False  | 
|     groupNum = sweepCfg[0]  | 
|     return curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_PubCDFBS_MapID % groupNum) == mapID  | 
|   | 
| ## »ñÈ¡¹«¹²CD¸±±¾É¨µ´ÅäÖÃÐÅÏ¢  | 
| def GetPubCDFBSweepCfg(curPlayer, mapID):  | 
|     PubCDFBSweepDict = ReadChConfig.GetEvalChConfig("PubCDFBSweep")  | 
|     for groupNum, sweepInfo in PubCDFBSweepDict.items():  | 
|         mapIDGroup = sweepInfo[0]  | 
|         if mapID not in mapIDGroup:  | 
|             continue  | 
|           | 
|         return groupNum, sweepInfo  | 
|       | 
|     return  | 
|   | 
| ## ¿ªÊ¼¹«¹²CD¸±±¾É¨µ´  | 
| def __DoStartPubCDFBSweep(curPlayer, mapID, lineID, cnt, isFinish, dataEx, groupNum, sweepInfo):  | 
|     curSweepMapID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_PubCDFBS_MapID % groupNum)  | 
|     if curSweepMapID > 0:  | 
|         GameWorld.DebugLog("¹«¹²CD¸±±¾É¨µ´ÖÐ, ÎÞ·¨É¨µ´!groupNum=%s,curSweepMapID=%s"   | 
|                            % (groupNum, curSweepMapID), curPlayer.GetPlayerID())  | 
|         return  | 
|       | 
|     if not FBLogic.OnStartPubCDFBSweep(curPlayer, mapID, lineID, cnt, dataEx):  | 
|         return  | 
|       | 
|     curTime = int(time.time())  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_PubCDFBS_MapID % groupNum, mapID)  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_PubCDFBS_LineID % groupNum, lineID)  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_PubCDFBS_Cnt % groupNum, cnt)  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_PubCDFBS_DataEx % groupNum, dataEx)  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_PubCDFBS_Time % groupNum, curTime)  | 
|     GameWorld.DebugLog("¹«¹²CD¸±±¾¿ªÊ¼É¨µ´ mapID=%s,lineID=%s,cnt=%s,dataEx=%s,groupNum=%s,curTime=%s"   | 
|                        % (mapID, lineID, cnt, dataEx, groupNum, curTime), curPlayer.GetPlayerID())  | 
|       | 
|       | 
|     Sync_PubFBSweepData(curPlayer, groupNum)  | 
|     return  | 
|   | 
| ## Íê³É¹«¹²CD¸±±¾É¨µ´  | 
| def __DoFinishPubCDFB(curPlayer, mapID, isFinish, groupNum, sweepInfo):  | 
|     playerID = curPlayer.GetPlayerID()  | 
|     curSweepMapID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_PubCDFBS_MapID % groupNum)  | 
|     if curSweepMapID <= 0 or curSweepMapID != mapID:  | 
|         GameWorld.DebugLog("δɨµ´ »ò ²»Êǵ±Ç°ÕýÔÚɨµ´µÄ¹«¹²CD¸±±¾, ÎÞ·¨Íê³É!curSweepMapID=%s,mapID=%s"   | 
|                            % (curSweepMapID, mapID), playerID)  | 
|         return  | 
|       | 
|     sweepTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_PubCDFBS_Time % groupNum)  | 
|     lineID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_PubCDFBS_LineID % groupNum)  | 
|     sweepCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_PubCDFBS_Cnt % groupNum)  | 
|     dataEx = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_PubCDFBS_DataEx % groupNum)  | 
|       | 
|     sweepNeedTime = sweepInfo[PCDFB_NeedTime] # µ¥´ÎºÄʱ  | 
|     finishCostGoldFormat = sweepInfo[PCDFB_FinishTimeGold]  | 
|     needTotalTime = sweepNeedTime * sweepCnt  | 
|       | 
|     curTime = int(time.time())  | 
|     passTime = max(0, curTime - sweepTime)  | 
|     second = max(0, needTotalTime - passTime)  | 
|       | 
|     # Õý³£Íê³É  | 
|     if isFinish == 2 and second > 0:  | 
|         GameWorld.DebugLog("ɨµ´Ê±¼äδµ½£¬ÎÞ·¨Íê³É£¬Ê£Óà%sÃë, mapID=%s" % (second, mapID), playerID)  | 
|         return  | 
|       | 
|     addDataDict = {"curTime":curTime, "startSweepTime":sweepTime, "sweepCnt":sweepCnt,   | 
|                    "needTotalTime":needTotalTime, "passTime":passTime, "remainSecond":second,   | 
|                    "costGold":0, "mapID":mapID, "lineID":lineID, "dataEx":dataEx, ChConfig.Def_Cost_Reason_SonKey:mapID}  | 
|       | 
|     # ×êʯÁ¢¼´Íê³É  | 
|     if isFinish == 1:  | 
|         costGold = eval(finishCostGoldFormat)  | 
|         if costGold > 0:  | 
|             addDataDict["costGold"] = costGold  | 
|             if not PlayerControl.PayMoney(curPlayer, IPY_GameWorld.TYPE_Price_Gold_Money, costGold,   | 
|                                           ChConfig.Def_Cost_FinishFBSweep, addDataDict):  | 
|                 return  | 
|       | 
|     GameWorld.DebugLog("¹«¹²CD¸±±¾É¨µ´Íê³É: %s" % str(addDataDict), playerID)  | 
|     # ¸ø½±Àø  | 
|     FBLogic.OnGivePubCDFBSweepPrize(curPlayer, mapID, lineID, sweepCnt, dataEx)  | 
|       | 
|     # ÖØÖÃɨµ´Êý¾Ý  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_PubCDFBS_MapID % groupNum, 0)  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_PubCDFBS_LineID % groupNum, 0)  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_PubCDFBS_Cnt % groupNum, 0)  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_PubCDFBS_DataEx % groupNum, 0)  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_PubCDFBS_Time % groupNum, 0)  | 
|     Sync_PubFBSweepData(curPlayer, groupNum)  | 
|     return  | 
|   | 
| ## Í¬²½¹«¹²CD¸±±¾É¨µ´ÐÅÏ¢  | 
| def Sync_PubFBSweepData(curPlayer, groupNum=-1):  | 
|       | 
|     PubCDFBSweepDict = ReadChConfig.GetEvalChConfig("PubCDFBSweep")  | 
|     allGroupNumList = PubCDFBSweepDict.keys()  | 
|     if groupNum == -1:  | 
|         groupNumList = allGroupNumList  | 
|     else:  | 
|         if groupNum not in allGroupNumList:  | 
|             return  | 
|         groupNumList = [groupNum]  | 
|           | 
|     pubSweepData = ChPyNetSendPack.tagMCPubFBSweepData()  | 
|     pubSweepData.Clear()  | 
|     pubSweepData.SweepDatList = []  | 
|       | 
|     for gNum in groupNumList:  | 
|         sweepInfo = ChPyNetSendPack.tagMCPubFBSweep()  | 
|         sweepInfo.Clear()  | 
|         sweepInfo.PubNum = gNum  | 
|         sweepInfo.FBMapID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_PubCDFBS_MapID % gNum)  | 
|         sweepInfo.LineID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_PubCDFBS_LineID % gNum)  | 
|         sweepInfo.SweepTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_PubCDFBS_Time % gNum)  | 
|         sweepInfo.SweepCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_PubCDFBS_Cnt % gNum)  | 
|         pubSweepData.SweepDatList.append(sweepInfo)  | 
|           | 
|     pubSweepData.Cnt = len(pubSweepData.SweepDatList)  | 
|     NetPackCommon.SendFakePack(curPlayer, pubSweepData)  | 
|     return  | 
|   | 
| #//A5 05 Íæ¼Ò¿ªÊ¼¸±±¾É¨µ´ #tagCMBeginFBWipeOut  | 
| #  | 
| #struct    tagCMBeginFBWipeOut  | 
| #{  | 
| #    tagHead         Head;  | 
| #    DWORD        MapID;  | 
| #    WORD        LineID;  | 
| #    BYTE        Cnt;    // É¨µ´´ÎÊý  | 
| #    BYTE        IsFinish;    // ÊÇ·ñÁ¢¼´Íê³É; 0-·ñ£»1-»¨Ç®Á¢¼´Íê³É£»2-¿Í»§¶Ë×ÔÐе¹¼ÆÊ±¼äµ½ºó·¢ËÍ2´ú±íÁìȡɨµ´Íê³É½±Àø  | 
| #    DWORD        DataEx;    //¸½´øÐÅÏ¢  | 
| #    BYTE        IsLittleHelper;    // ÊÇ·ñСÖúÊÖɨµ´  | 
| #};  | 
| def OnPlayerFBWipeOut(playerIndex, clientData, tick):  | 
|     curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(playerIndex)  | 
|       | 
|     if not GameWorld.CheckPlayerTick(curPlayer, ChConfig.TYPE_Player_Tick_BeginFBWipeOut, tick):  | 
|         GameWorld.DebugLog("Íæ¼Ò¸±±¾É¨µ´ÇëÇóCDÖÐ...", curPlayer.GetPlayerID())  | 
|         return  | 
|       | 
|     mapID = clientData.MapID  | 
|     lineID = clientData.LineID  | 
|     cnt = clientData.Cnt  | 
|     #isFinish = clientData.IsFinish  | 
|     isFinish = 1 # ÔÝʱĬÈÏ1£¬Ö®ºóÓÐÐèҪɨµ´µÈ´ýµÄÔÙ˵  | 
|     dataEx = clientData.DataEx  | 
|     isLittleHelper = clientData.IsLittleHelper  | 
|     if isLittleHelper:  | 
|         if not GameFuncComm.GetFuncCanUse(curPlayer, ShareDefine.GameFuncID_LittleHelper):  | 
|             GameWorld.DebugLog("Íæ¼ÒûÓÐСÖúÊÖ¹¦ÄÜȨÏÞ£¡", curPlayer.GetPlayerID())  | 
|             return  | 
|       | 
|     if cnt <= 0:  | 
|         return  | 
|       | 
|     fbIpyData = FBCommon.GetFBIpyData(mapID)  | 
|     if FBCommon.GetRecordMapID(GameWorld.GetMap().GetMapID()) == FBCommon.GetRecordMapID(mapID):  | 
|         if fbIpyData and fbIpyData.GetDayTimes():#ûÓÐÏÞÖÆ½øÈë´ÎÊýµÄ²»ÏÞÖÆÔÚÄ¿±êµØÍ¼É¨µ´  | 
|             GameWorld.DebugLog("Íæ¼ÒÔÚɨµ´Ä¿±êµØÍ¼ÖУ¬ÎÞ·¨É¨µ´£¡mapID=%s" % mapID)  | 
|             return  | 
|       | 
|       | 
|     fbLineIpyData = FBCommon.GetFBLineIpyData(mapID, lineID)  | 
|     if not fbLineIpyData:  | 
|         GameWorld.DebugLog("ÕÒ²»µ½¸Ã¸±±¾Ïß·£¬ÎÞ·¨É¨µ´£¡mapID=%s, lineID=%s" % (mapID, lineID))  | 
|         return  | 
|       | 
|     if FBCommon.CheckCanEnterFBComm(curPlayer, mapID, lineID, fbIpyData, fbLineIpyData, cnt) != ShareDefine.EntFBAskRet_OK:  | 
|         return  | 
|     costMoneyList = []  | 
|     sweepCostindexList = []  | 
|     sweepCostCnt = 0  | 
|     itemPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptItem)  | 
|       | 
|     if fbLineIpyData:  | 
|         #ɨµ´µÈ¼¶ÅÐ¶Ï  | 
|         sweepLVLimit = fbLineIpyData.GetSweepLVLimit()  | 
|         if sweepLVLimit and curPlayer.GetLV() < sweepLVLimit:  | 
|             GameWorld.DebugLog('Íæ¼Ò¸±±¾É¨µ´,µÈ¼¶²»×㣡mapID=%s, lineID=%s, playerLV=%s, sweepLVLimit=%s'   | 
|                                % (mapID, lineID, curPlayer.GetLV(), sweepLVLimit), curPlayer.GetPlayerID())  | 
|             return  | 
|           | 
|         #ɨµ´µÀ¾ßÅжϣ¬Ð¡ÖúÊÖ²»ÏûºÄɨµ´µÀ¾ß  | 
|         sweepItemID = fbLineIpyData.GetSweepItemID()  | 
|         if sweepItemID and not isLittleHelper:  | 
|             sweepItemCnt = fbLineIpyData.GetSweepCostCnt()  | 
|             sweepCostCnt = sweepItemCnt * cnt  | 
|             #isEnough, sweepCostindexList = ItemCommon.GetItem_FromPack_ByID(sweepItemID, itemPack, sweepCostCnt)  | 
|             isEnough, sweepCostindexList, hasBind, lackCnt = ItemCommon.GetItem_FromPack_ByID_ExEx(sweepItemID, itemPack, sweepCostCnt)  | 
|             if not isEnough:  | 
|                 itemPrice = ItemCommon.GetShopItemPrice(sweepItemID, IPY_GameWorld.TYPE_Price_Gold_Money)  | 
|                 if itemPrice:  | 
|                     costMoney = itemPrice * lackCnt  | 
|                     costMoneyList = PlayerControl.HaveMoneyEx(curPlayer, ShareDefine.TYPE_Price_Gold_Paper_Money, costMoney)  | 
|                 if not costMoneyList:  | 
|                     GameWorld.DebugLog("ɨµ´ÏûºÄµÀ¾ß²»×ã, mapID=%s,lineID=%s,sweepItemID=%s,sweepCostCnt=%s"   | 
|                                    % (mapID, lineID, sweepItemID, sweepCostCnt), curPlayer.GetPlayerID())  | 
|                     return  | 
|   | 
|               | 
|           | 
|     #¹«¹²CDɨµ´Ä£Ê½ÔÝÆÁ±Î£¬ÓÐÐèÒªÔÙÐÞ¸Ä  | 
|     #===============================================================================================  | 
|     # groupNum = -1  | 
|     # sweepInfo = None  | 
|     # PubCDFBSweepDict = ReadChConfig.GetEvalChConfig("PubCDFBSweep")  | 
|     # for gNum, sInfo in PubCDFBSweepDict.items():  | 
|     #    if mapID in sInfo[PCDFB_MapIDList]:  | 
|     #        groupNum = gNum  | 
|     #        sweepInfo = sInfo  | 
|     #        break  | 
|     #          | 
|     # # ¹«¹²CD¸±±¾É¨µ´  | 
|     # if groupNum >= 0:  | 
|     #    if not isFinish:  | 
|     #        __DoStartPubCDFBSweep(curPlayer, mapID, lineID, cnt, isFinish, dataEx, groupNum, sweepInfo)  | 
|     #    else:  | 
|     #        __DoFinishPubCDFB(curPlayer, mapID, isFinish, groupNum, sweepInfo)  | 
|     #    return  | 
|     #===============================================================================================  | 
|       | 
|     # ¸±±¾ÊÇ·ñ¿Éɨµ´, ÕâÀïÖ»Åжϸ±±¾×ÔÉíµÄÌØÊâÌõ¼þ, ¹«¹²Ìõ¼þÉÏÃæÒѾÅÐ¶Ï  | 
|     if not FBLogic.OnPlayerFBSweepAsk(curPlayer, mapID, lineID, cnt, isFinish, dataEx):  | 
|         return  | 
|       | 
|     PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_FeastRedPack_FBSweep, 1, [mapID])  | 
|       | 
|     #¿Û³ýɨµ´µÀ¾ß  | 
|     if sweepCostindexList and sweepCostCnt:  | 
|         ItemCommon.ReduceItem(curPlayer, itemPack, sweepCostindexList, sweepCostCnt, False, 'FBSweepCostItem')  | 
|     if costMoneyList:  | 
|         infoDict = {"MapID":mapID, "LineID":lineID, 'SweepCount':cnt}  | 
|         for moneyType, moneyNum in costMoneyList:  | 
|             if not PlayerControl.PayMoney(curPlayer, moneyType, moneyNum, ChConfig.Def_Cost_FBSweep, infoDict):  | 
|                 return False, hasBind  | 
|       | 
|     #ÐèÏȿ۳ýÃÅÆ±, ÔÙÔö¼Ó´ÎÊý, ·ñÔò¿ÉÄܵ¼Ö¿۳ýµÄÊýÁ¿´íÎó  | 
|     FBCommon.DelFBEnterTicket(curPlayer, mapID, lineID, cnt)  | 
|           | 
|     #Ôö¼Ó¸±±¾½øÈë´ÎÊý  | 
|     if fbIpyData and fbIpyData.GetDayTimes():  | 
|         FBCommon.AddEnterFBCount(curPlayer, mapID, cnt)  | 
|       | 
|     helpIpyData = IpyGameDataPY.GetIpyGameData("FBHelpBattle", mapID, lineID)  | 
|     if helpIpyData:  | 
|         FBHelpBattle.SendGameServer_SweepCallHelpBattlePlayer(curPlayer, mapID, lineID)  | 
|         return  | 
|       | 
|     #ɨµ´½á¹û¸ø½±ÀøµÈ  | 
|     FBLogic.OnPlayerFBSweepResult(curPlayer, mapID, lineID, cnt, isFinish, dataEx)  | 
|     return  | 
|   | 
|   | 
| #// A5 1B ¹ºÂòÌôÕ½¸±±¾¾«Á¦ #tagCMBuyFBEnergy  | 
| #  | 
| #struct    tagCMBuyFBEnergy  | 
| #{  | 
| #    tagHead         Head;  | 
| #};  | 
| def OnPlayerBuyFBEnergy(playerIndex, clientData, tick):  | 
|     #curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(playerIndex)  | 
|     return  | 
|   | 
|   | 
| ## Íæ¼Ò¸±±¾¹¦ÄÜʱ¼ä´¦Àí  | 
| def DoPlayerFBTimeProcess(curPlayer, tick):  | 
|       | 
|     checkInterval = ChConfig.TYPE_Player_Tick_Time[ChConfig.TYPE_Player_Tick_FBTimeProcess]  | 
|     if tick - curPlayer.GetTickByType(ChConfig.TYPE_Player_Tick_FBTimeProcess) < checkInterval:  | 
|         return   | 
|       | 
|     curPlayer.SetTickByType(ChConfig.TYPE_Player_Tick_FBTimeProcess, tick)  | 
|       | 
|     # ÁìÖ÷°ÔÒµÍæ¼Ò¹¦ÄÜʱ¼ä´¦Àí  | 
|     FBCommon.RegainFBCntProcess(curPlayer)  | 
|     return  | 
|   | 
|   | 
| #// B1 02 ÁìÈ¡¶à±¶¸±±¾½±Àø #tagCMGetMultiFBPrize  | 
| #  | 
| #struct    tagCMGetMultiFBPrize  | 
| #{  | 
| #    tagHead         Head;  | 
| #    DWORD        MapID;  | 
| #    WORD        LineID;  | 
| #    WORD        Percent;    // ¶îÍâ½±Àø°Ù·Ö±È½±ÀøµÈ¼¶  | 
| #};  | 
| def OnPlayerGetMultiFBPrize(playerIndex, clientData, tick):  | 
|     curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(playerIndex)  | 
|     mapID = clientData.MapID  | 
|     lineID = clientData.LineID  | 
|     prizeExLV = clientData.Percent  | 
|     FBLogic.OnGetMultiFBPrize(curPlayer, mapID, lineID, prizeExLV)  | 
|     return  | 
|   | 
|   | 
| #//A5 60 ÖØÖø±±¾ÌôÕ½´ÎÊý #tagCMResetFBJoinCnt  | 
| #  | 
| #struct tagCMResetFBJoinCnt  | 
| #{  | 
| #    tagHead        Head;  | 
| #};  | 
| def OnPlayerResetFBJoinCnt(playerIndex, clientData, tick):  | 
|     curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(playerIndex)  | 
|     return  | 
|   | 
|   | 
| #// B1 01 ¿Í»§¶Ë¸±±¾·¢ËͽáÊø #tagCMClientEndFB  | 
| #  | 
| #struct    tagCMClientEndFB  | 
| #{  | 
| #    tagHead         Head;  | 
| #    DWORD        MapID;  | 
| #    WORD        LineID;  | 
| #    DWORD        Data;    //¸±±¾Êý¾Ý  | 
| #};  | 
| def OnClientEndFB(playerIndex, clientData, tick):  | 
|     curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(playerIndex)  | 
|     mapID = clientData.MapID  | 
|     lineID = clientData.LineID  | 
|     data1 = clientData.Data1  | 
|     data2 = clientData.Data2  | 
|     dataList = [data1, data2]  | 
|     FBLogic.OnClientEndFB(curPlayer, mapID, lineID, dataList)  | 
|     GameWorld.DebugLog('    ¿Í»§¶Ë¸±±¾·¢ËͽáÊømapID=%s,lineID=%s,dataList=%s'%(mapID,lineID,dataList))  | 
|     return  | 
|   | 
|   | 
| #// B1 04 ¿Í»§¶Ë·¢ËÍ¿ªÊ¼¸±±¾ #tagCMClientStartFB  | 
| #  | 
| #struct    tagCMClientStartFB  | 
| #{  | 
| #    tagHead         Head;  | 
| #};  | 
| def OnClientStartFB(playerIndex, clientData, tick):  | 
|     curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(playerIndex)  | 
|     FBLogic.OnClientStartFB(curPlayer, tick)  | 
|     return  | 
|   | 
| #// A2 31 Ç°¶Ë¿ªÊ¼×Ô¶¨Ò峡¾° #tagCMClientStartCustomScene  | 
| #  | 
| #struct    tagCMClientStartCustomScene  | 
| #{  | 
| #    tagHead        Head;  | 
| #    DWORD        MapID;  | 
| #    WORD        FuncLineID;  | 
| #};  | 
| def OnClientStartCustomScene(index, clientData, tick):  | 
|     curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)  | 
|     mapID = clientData.MapID  | 
|     funcLineID = clientData.FuncLineID  | 
|     DoEnterCustomScene(curPlayer, mapID, funcLineID, tick)  | 
|     return  | 
|   | 
| #// A2 33 Ç°¶ËÍ˳ö×Ô¶¨Ò峡¾° #tagCMClientExitCustomScene  | 
| #  | 
| #struct    tagCMClientExitCustomScene  | 
| #{  | 
| #    tagHead        Head;  | 
| #};  | 
| def OnClientExitCustomScene(index, clientData, tick):  | 
|     curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)  | 
|     DoExitCustomScene(curPlayer)  | 
|     return  | 
|   | 
| def DoEnterCustomScene(curPlayer, mapID, lineID, tick):  | 
|     ## ½øÈë×Ô¶¨Ò峡¾°×´Ì¬  | 
|     playerID = curPlayer.GetPlayerID()  | 
|     GameWorld.Log("Íæ¼ÒÇëÇó½øÈë×Ô¶¨Ò峡¾°!mapID=%s,lineID=%s" % (mapID, lineID), playerID)  | 
|     if curPlayer.GetDictByKey(ChConfig.Def_PlayerKey_ClientCustomScene):  | 
|         curMapID = PlayerControl.GetCustomMapID(curPlayer)  | 
|         curLineID = PlayerControl.GetCustomLineID(curPlayer)  | 
|         if mapID == curMapID and lineID == curLineID:  | 
|             GameWorld.Log("    Íæ¼Òµ±Ç°ÒѾÔÚ×Ô¶¨Ò峡¾°ÖУ¡ÎÞÐèÖØÐÂÇëÇó£¡", playerID)  | 
|             result = 1  | 
|         else:  | 
|             GameWorld.Log("    Íæ¼Òµ±Ç°ÔÚ²»Í¬µÄ×Ô¶¨Ò峡¾°ÖУ¡²»ÔÊÐí½øÈ룡curMapID=%s,curLineID=%s"   | 
|                           % (curMapID, curLineID), playerID)  | 
|             result = 0  | 
|         StartCustomSceneResult(curPlayer, mapID, lineID, result)  | 
|         return  | 
|       | 
|     #½øÈ븱±¾Í¨Óüì²é  | 
|     if mapID:  | 
|         fbIpyData = FBCommon.GetFBIpyData(mapID)  | 
|         fbLineIpyData = FBCommon.GetFBLineIpyData(mapID, lineID)  | 
|         if PlayerControl.CheckMoveToFB(curPlayer, mapID, lineID, fbIpyData, fbLineIpyData, tick) != ShareDefine.EntFBAskRet_OK:  | 
|             StartCustomSceneResult(curPlayer, mapID, lineID, 0)  | 
|             return  | 
|       | 
|     PlayerControl.SetPlayerSightLevel(curPlayer, curPlayer.GetID())  | 
|           | 
|     curPlayer.SetDict(ChConfig.Def_PlayerKey_ClientCustomScene, 1) # ÓÉÓÚǰ¶Ë²»Ò»¶¨Óз¢mapID£¬ËùÒÔÕâÀï¶îÍâ¼Ç¼Õâ¸ö״̬£¬²»ÄÜÖ±½ÓÓÃmapIDÅÐ¶Ï  | 
|     curPlayer.SetDict(ChConfig.Def_PlayerKey_ClientCustomSceneStepTick, tick)  | 
|     PlayerControl.SetCustomMap(curPlayer, mapID, lineID)  | 
|     NPCCommon.ClearPriWoodPile(curPlayer)  | 
|     GameWorld.Log("Íæ¼Ò¿ªÊ¼×Ô¶¨Ò峡¾°!mapID=%s,lineID=%s" % (mapID, lineID), playerID)  | 
|     if mapID:  | 
|         PetControl.DoLogic_PetLoadMapOK(curPlayer)  | 
|         FBLogic.OnEnterCustomScene(curPlayer, mapID, lineID)  | 
|           | 
|     #ĬÈÏ»ØÂúѪ  | 
|     if curPlayer.GetHP() < curPlayer.GetMaxHP():  | 
|         curPlayer.SetHP(curPlayer.GetMaxHP())  | 
|           | 
|     #֪ͨ½øÈë״̬  | 
|     StartCustomSceneResult(curPlayer, mapID, lineID, 1)  | 
|     return  | 
|   | 
| def StartCustomSceneResult(curPlayer, mapID, lineID, result):  | 
|     if result != 1:  | 
|         DoExitCustomScene(curPlayer)  | 
|     resultPack = ChPyNetSendPack.tagMCStartCustomSceneResult()  | 
|     resultPack.MapID = mapID  | 
|     resultPack.FuncLineID = lineID  | 
|     resultPack.Result = result  | 
|     NetPackCommon.SendFakePack(curPlayer, resultPack)  | 
|     return  | 
|   | 
| def DoExitCustomScene(curPlayer):  | 
|     ## Í˳ö×Ô¶¨Ò峡¾°×´Ì¬  | 
|     PlayerControl.SetPlayerSightLevel(curPlayer, 0)  | 
|     mapID = PlayerControl.GetCustomMapID(curPlayer)  | 
|     lineID = PlayerControl.GetCustomLineID(curPlayer)  | 
|     curPlayer.SetDict(ChConfig.Def_PlayerKey_ClientCustomScene, 0)  | 
|     curPlayer.SetDict(ChConfig.Def_PlayerKey_ClientCustomSceneStepTick, 0)  | 
|     curPlayer.SetDict(ChConfig.Def_PlayerKey_ClientCustomSceneGrade, 0)  | 
|     PlayerControl.SetCustomMap(curPlayer, 0, 0)  | 
|     if mapID and FBCommon.GetCustomMapStep(curPlayer, mapID, lineID) != ChConfig.CustomMapStep_Over:  | 
|         FBCommon.SetCustomMapStep(curPlayer, mapID, lineID, ChConfig.CustomMapStep_Over)  | 
|     NPCCommon.ClearPriWoodPile(curPlayer)  | 
|       | 
|     #ĬÈÏ»ØÂúѪ  | 
|     if curPlayer.GetHP() > 0 and curPlayer.GetPlayerAction() != IPY_GameWorld.paDie and curPlayer.GetHP() < curPlayer.GetMaxHP():  | 
|         curPlayer.SetHP(curPlayer.GetMaxHP())  | 
|           | 
|     GameWorld.Log("Íæ¼ÒÍ˳ö×Ô¶¨Ò峡¾°!", curPlayer.GetPlayerID())  | 
|     return  | 
|   | 
| #// B1 0A ¸±±¾¹ºÂòbuff #tagCMFBBuyBuff  | 
| #struct    tagCMFBBuyBuff  | 
| #{  | 
| #    tagHead         Head;  | 
| #    DWORD        MapID;  | 
| #    WORD        MoneyCnt;  | 
| #};  | 
| def OnFBBuyBuff(playerIndex, clientData, tick):  | 
|     curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(playerIndex)  | 
|     playerID = curPlayer.GetPlayerID()  | 
|     mapID = clientData.MapID  | 
|     moneyCnt = clientData.MoneyCnt  | 
|     ipyData = IpyGameDataPY.GetIpyGameData('FBBuyBuff', mapID, moneyCnt)  | 
|     if not ipyData:  | 
|         return  | 
|     addBuffID = ipyData.GetBuffID()  | 
|     curSkill = GameWorld.GetGameData().GetSkillBySkillID(addBuffID)  | 
|     if not curSkill:  | 
|         return  | 
|     crossMapID = PlayerControl.GetCrossMapID(curPlayer)  | 
|     if crossMapID and mapID !=crossMapID:  | 
|         return  | 
|     if not crossMapID and mapID != GameWorld.GetMap().GetMapID():  | 
|         return  | 
|       | 
|     curTime = int(time.time())  | 
|     #ÅжÏCD   | 
|     timeKey = (mapID, moneyCnt)  | 
|     lastTime = PyGameData.g_fbBuyBuffTimeDict.get(playerID, {}).get(timeKey, 0)  | 
|     if lastTime and curTime - lastTime < ipyData.GetBuffCD():  | 
|         GameWorld.DebugLog('¸±±¾¹ºÂòbuff CDδµ½ ')  | 
|         return  | 
|   | 
|     #¿ÛÇ®  | 
|     infoDict =  {"MapID":mapID, "addBuffID":addBuffID}  | 
|     if not PlayerControl.PayMoney(curPlayer, IPY_GameWorld.TYPE_Price_Gold_Money, moneyCnt, ChConfig.Def_Cost_FBBuyBuff, infoDict):  | 
|         return  | 
|     if playerID not in PyGameData.g_fbBuyBuffTimeDict:  | 
|         PyGameData.g_fbBuyBuffTimeDict[playerID] = {}  | 
|     PyGameData.g_fbBuyBuffTimeDict[playerID][timeKey] = curTime  | 
|     NotifyBuyFBBuffInfo(curPlayer)  | 
|     if crossMapID:  | 
|         msgDict = {"PlayerID":curPlayer.GetPlayerID(), "buffID":addBuffID}  | 
|         GameWorld.SendMsgToCrossServer(ShareDefine.ClientServerMsg_AddBuff, msgDict)  | 
|         GameWorld.DebugLog("¿ç·þÖÐÇëÇó¸´»î, crossMapID=%s,msgDict=%s" % (crossMapID, msgDict), playerID)  | 
|         return  | 
|   | 
|     SkillShell.__DoLogic_AddBuff(curPlayer, curPlayer, curSkill, False, tick, 0, 0)  | 
|     #SkillCommon.AddBuffBySkillType(curPlayer, addBuffID, tick)  | 
|     return  | 
|   | 
| def NotifyBuyFBBuffInfo(curPlayer):  | 
|     playerID = curPlayer.GetPlayerID()  | 
|     buffTimeDict = PyGameData.g_fbBuyBuffTimeDict.get(playerID, {})  | 
|     if not buffTimeDict:  | 
|         return  | 
|     packData = ChPyNetSendPack.tagMCFBBuyBuffInfo()  | 
|     packData.InfoList = []  | 
|     for timeKey, buyTime in buffTimeDict.items():  | 
|         mapID, moneyCnt = timeKey  | 
|         timeInfo = ChPyNetSendPack.tagMCFBBuyBuffTime()  | 
|         timeInfo.MapID = mapID  | 
|         timeInfo.MoneyCnt = moneyCnt  | 
|         timeInfo.BuyTime = buyTime  | 
|         packData.InfoList.append(timeInfo)  | 
|     packData.Cnt = len(packData.InfoList)  | 
|     NetPackCommon.SendFakePack(curPlayer, packData)  | 
|     return  |