| #!/usr/bin/python  | 
| # -*- coding: GBK -*-  | 
| #-------------------------------------------------------------------------------  | 
| #  | 
| ##@package GameWorldLogic.FBProcess.FBHelpBattle  | 
| #  | 
| # @todo:¸±±¾Öúսϵͳ  | 
| # @author hxp  | 
| # @date 2018-11-24  | 
| # @version 1.0  | 
| #  | 
| # ÏêϸÃèÊö: ¸±±¾Öúսϵͳ  | 
| #  | 
| #-------------------------------------------------------------------------------  | 
| #"""Version = 2018-11-24 22:30"""  | 
| #-------------------------------------------------------------------------------  | 
|   | 
| import GameWorld  | 
| import ChConfig  | 
| import PlayerControl  | 
| import PlayerBillboard  | 
| import ChPyNetSendPack  | 
| import NetPackCommon  | 
| import PlayerViewCacheTube  | 
| import FBCommon  | 
| import IpyGameDataPY  | 
| import ShareDefine  | 
| import PyGameData  | 
| import random  | 
| import GameMap  | 
| import NPCCommon  | 
| import FBLogic  | 
| import PlayerVip  | 
| import IPY_GameWorld  | 
| import PlayerActivity  | 
|   | 
| import time  | 
|   | 
| def DoPlayerOnDay(curPlayer):  | 
|     checkInInfo = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_HelpBattleCheckInCount)  | 
|     checkInCount = checkInInfo / 10 # ÀÛ¼ÆµÇ¼Ç  | 
|     todayIsCheckIn = checkInInfo % 10 # ½ñÌìÊÇ·ñÒÑµÇ¼Ç  | 
|     if todayIsCheckIn:  | 
|         checkInInfo = checkInCount * 10 + 0  | 
|         PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_HelpBattleCheckInCount, checkInInfo)  | 
|         SyncCheckInState(curPlayer, 0, False)  | 
|       | 
|     # ÖØÖÃÿÈÕÒÑ»ñµÃÏÉÔµ±Ò  | 
|     ondaySetXianyuanCoin = 0  | 
|     ondayLoginSetXianyuanCoin = curPlayer.GetDictByKey(ChConfig.Def_PDict_TodayXianyuanCoinOnLogin)  | 
|     if ondayLoginSetXianyuanCoin:  | 
|         # ÕâÀï×öʱ¼ä±È½Ï£¬Ô¤·ÀÍæ¼ÒµÇ¼ºó¾ÍûÓÐÔÙÇл»µØÍ¼£¬ÔÙ´ÎÔڸõØÍ¼¹ýÌì»áµ¼ÖÂÉèÖÃÖµ´íÎóÎÊÌâ  | 
|         loginAddCoinTime = curPlayer.GetDictByKey(ChConfig.Def_PDict_LoginAddTodayXianyuanCoinTime)  | 
|         if GameWorld.CheckTimeIsSameServerDayEx(loginAddCoinTime):  | 
|             ondaySetXianyuanCoin = ondayLoginSetXianyuanCoin  | 
|             GameWorld.DebugLog("Íæ¼Ò¹ýÌìʱ£¬µÇ¼Ôö¼ÓÏÉÔµ±ÒÓÐÖµ£¬ÈÔÈ»ÊÇͬһÌ죬ÏÉÔµ±ÒÖØÖÃΪµÇ¼ʱÔö¼ÓµÄÏÉÔµ±Ò£¡ondayLoginSetXianyuanCoin=%s" % ondayLoginSetXianyuanCoin)  | 
|         else:  | 
|             GameWorld.DebugLog("Íæ¼Ò¹ýÌìʱ£¬µÇ¼Ôö¼ÓÏÉÔµ±ÒÓÐÖµ£¬µ«ÊDz»ÊÇͬһÌìÁË£¬ÏÉÔµ±ÒÖØÖÃΪ0£¡")  | 
|     PlayerControl.SetTodayXianyuanCoin(curPlayer, ondaySetXianyuanCoin)  | 
|     GameWorld.DebugLog("Íæ¼Ò¹ýÌìÉèÖýñÈÕÒÑ»ñµÃÏÉÔµ±Ò: ondaySetXianyuanCoin=%s,ondayLoginSetXianyuanCoin=%s"   | 
|                        % (ondaySetXianyuanCoin, ondayLoginSetXianyuanCoin))  | 
|     return  | 
|   | 
| def DoPlayerLogin(curPlayer):  | 
|     checkInInfo = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_HelpBattleCheckInCount)  | 
|     todayIsCheckIn = checkInInfo % 10 # ½ñÌìÊÇ·ñÒÑµÇ¼Ç  | 
|     if todayIsCheckIn:  | 
|         SyncCheckInState(curPlayer, 1, True)  | 
|     return  | 
|   | 
| def SyncCheckInState(curPlayer, checkInState, isLogin):  | 
|     ## Í¬²½µÇ¼Ç״̬  | 
|     checkInPack = ChPyNetSendPack.tagMCHelpBattleCheckInResult()  | 
|     checkInPack.IsOK = checkInState  | 
|     checkInPack.IsLogin = int(isLogin)  | 
|     NetPackCommon.SendFakePack(curPlayer, checkInPack)  | 
|     return  | 
|   | 
| def GameServer_FBHelpBattleResult(curPlayer, msgList, tick):  | 
|     ## GameServer½á¹û·µ»Ø´¦Àí  | 
|       | 
|     if not msgList:  | 
|         return  | 
|       | 
|     cmd = msgList[0]  | 
|     # µÇ¼Ç  | 
|     if cmd == "CheckIn":  | 
|         __OnHelpBattleCheckInResult(curPlayer, msgList, tick)  | 
|           | 
|     # Ë¢Ð  | 
|     if cmd == "Refresh":  | 
|         __OnHelpBattleRefreshResult(curPlayer, msgList, tick)  | 
|           | 
|     # ÖúÕ½¼Ç¼  | 
|     if cmd == "HelpRecord":  | 
|         __OnHelpBattleRecord(curPlayer, msgList, tick)  | 
|           | 
|     return  | 
|   | 
| #// B1 05 ÖúÕ½µÇ¼Ç #tagCMHelpBattleCheckIn  | 
| #  | 
| #struct    tagCMHelpBattleCheckIn  | 
| #{  | 
| #    tagHead         Head;  | 
| #};  | 
| def OnHelpBattleCheckIn(index, clientData, tick):  | 
|     curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)  | 
|     checkInInfo = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_HelpBattleCheckInCount)  | 
|     checkInCount = checkInInfo / 10 # ÀÛ¼ÆµÇ¼Ç  | 
|     todayIsCheckIn = checkInInfo % 10 # ½ñÌìÊÇ·ñÒÑµÇ¼Ç  | 
|     if todayIsCheckIn:  | 
|         GameWorld.DebugLog("µ±ÌìÒѵǼǣ¬²»ÐèÒªÖØ¸´µÇ¼Ç£¡", curPlayer.GetPlayerID())  | 
|         return  | 
|     fightPower = curPlayer.GetFightPower()  | 
|     msgInfo = str(["CheckIn", checkInCount, fightPower])  | 
|     GameWorld.GetPlayerManager().GameServer_QueryPlayerResult(curPlayer.GetID(), 0, 0, "FBHelpBattle", msgInfo, len(msgInfo))  | 
|     return  | 
|   | 
| def __OnHelpBattleCheckInResult(curPlayer, msgList, tick):  | 
|     ## µÇ¼Ç·µ»Ø  | 
|     cmd, checkInCount, fightPower, isOK, haveViewCache = msgList  | 
|     if isOK:  | 
|         checkInInfo = (checkInCount + 1) * 10 + 1  | 
|         PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_HelpBattleCheckInCount, checkInInfo)  | 
|         PlayerActivity.AddDailyActionFinishCnt(curPlayer, ShareDefine.DailyActionID_HelpBattleCheckIn)  | 
|           | 
|         # Ã»ÓÐÊý¾Ý»º´æµÄ»°£¬ÂíÉÏͬ²½Ò»´Î  | 
|         if not haveViewCache:  | 
|             PlayerViewCacheTube.UpdateGameServerPlayerCache(curPlayer, tick, False)  | 
|               | 
|     SyncCheckInState(curPlayer, 1, False)  | 
|       | 
|     GameWorld.DebugLog("FBHelpBattleResult: %s,checkInCount=%s,fightPower=%s,isOK=%s,haveViewCache=%s"   | 
|                        % (cmd, checkInCount, fightPower, isOK, haveViewCache), curPlayer.GetPlayerID())  | 
|     return  | 
|   | 
| #// B1 06 ÖúÕ½ÕÙ»½ #tagCMHelpBattleCall  | 
| #  | 
| #struct    tagCMHelpBattleCall  | 
| #{  | 
| #    tagHead         Head;  | 
| #    BYTE        IsOneKeyCall;    // ÊÇ·ñÒ»¼üÕÙ»½  | 
| #    DWORD        PlayerID;        // ÕÙ»½µÄÍæ¼ÒID£¬´óÓÚ1СÓÚ100´ú±í»úÆ÷ÈË  | 
| #    BYTE        IsGoldCall;    // ÊÇ·ñÏÉÓñÕÙ»½  | 
| #};  | 
| def OnHelpBattleCall(index, clientData, tick):  | 
|     curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)  | 
|     isOneKeyCall = clientData.IsOneKeyCall  | 
|     calledPlayerID = clientData.PlayerID  | 
|     #isGoldCall = clientData.IsGoldCall  | 
|       | 
|     playerID = curPlayer.GetPlayerID()  | 
|     gameFB = GameWorld.GetGameFB()  | 
|       | 
|     mapID = FBCommon.GetRecordMapID(curPlayer.GetMapID())  | 
|     funcLineID = FBCommon.GetFBPropertyMark()  | 
|     ipyData = IpyGameDataPY.GetIpyGameData("FBHelpBattle", mapID, funcLineID)  | 
|     if not ipyData:  | 
|         return  | 
|       | 
|     helpBattlePlayerDict = PyGameData.g_fbHelpBattlePlayerDict.get(playerID, {})  | 
|     maxHelpPlayerCount = IpyGameDataPY.GetFuncCfg("HelpBattleCall", 2) # ×î´óÖúÕ½ÈËÊý  | 
|     calledCount = 0  | 
|     freePlayerIDList = []  | 
|     helpNPCRobotIDList = []  | 
|     for helpPlayerID, helpPlayerInfoDict in helpBattlePlayerDict.items():  | 
|         objID = gameFB.GetGameFBDictByKey(ChConfig.Def_FB_HelpBattleFBObjID % helpPlayerID)  | 
|         if objID:  | 
|             if helpPlayerID == calledPlayerID:  | 
|                 GameWorld.DebugLog("¸ÃÖúÕ½»úÆ÷ÈËIDÒѾÕÙ»½¹ý£¬²»ÔÊÐíÖØ¸´ÕÙ»½!calledPlayerID=%s" % calledPlayerID)  | 
|                 return  | 
|             calledCount += 1  | 
|         # Í³¼ÆÃâ·ÑµÄδÕÙ»½µÄ  | 
|         elif not helpPlayerInfoDict.get("NeedGoldCall", 0):  | 
|             if "Name" in helpPlayerInfoDict:  | 
|                 freePlayerIDList.append(helpPlayerID)  | 
|             else:  | 
|                 helpNPCRobotIDList.append(helpPlayerID)  | 
|     if calledCount >= maxHelpPlayerCount:  | 
|         GameWorld.Log("ÒѾÕÙ»½ÂúÈËÊý£¡ÎÞ·¨ÔÙÕÙ»½£¡calledCount=%s" % calledCount, playerID)  | 
|         return  | 
|       | 
|     calledPlayerDict = {} # {±»ÕÙ»½µÄÍæ¼ÒID:¹ØÏµ, ...}  | 
|     # ÓÅÏÈÕÙ»½Ãâ·ÑÍæ¼Ò¾µÏñ£¬²»×ã²ÅÕÐNPC£¬Ôݲ»×öÕ½Á¦ÅÅÐò  | 
|     if isOneKeyCall:  | 
|         lackCount = maxHelpPlayerCount - calledCount  | 
|         if freePlayerIDList:  | 
|             randIDList = random.sample(freePlayerIDList, min(lackCount, len(freePlayerIDList)))  | 
|             lackCount -= len(randIDList)  | 
|             for randID in randIDList:  | 
|                 helpPlayerInfoDict = helpBattlePlayerDict[randID]  | 
|                 calledPlayerDict[randID] = helpPlayerInfoDict.get("Relation", 0)  | 
|         if lackCount > 0 and helpNPCRobotIDList:  | 
|             for robotID in helpNPCRobotIDList[:lackCount]:  | 
|                 calledPlayerDict[robotID] = 0       | 
|                   | 
|         if calledCount + len(calledPlayerDict) < maxHelpPlayerCount:  | 
|             GameWorld.ErrLog("ÎÞ·¨Ò»¼üÕÙ»½!ÈËÊý²»×ã! calledCount=%s,calledPlayerDict=%s,maxHelpPlayerCount=%s"   | 
|                              % (calledCount, calledPlayerDict, maxHelpPlayerCount), playerID)  | 
|             return  | 
|     else:  | 
|         if calledPlayerID not in helpBattlePlayerDict:  | 
|             GameWorld.ErrLog("²»´æÔÚ¸ÃÖúÕ½Íæ¼Ò£¬ÎÞ·¨ÕÙ»½£¡calledPlayerID=%s" % (calledPlayerID), playerID)  | 
|             return  | 
|         helpPlayerInfoDict = helpBattlePlayerDict[calledPlayerID]  | 
|         if helpPlayerInfoDict.get("NeedGoldCall", 0):  | 
|             goldCallCost = IpyGameDataPY.GetFuncCfg("HelpBattleCall", 5) # ¸¶·ÑÕÙ»½ÏûºÄÏÉÓñ£¬ÓÅÏÈÏûºÄ°óÓñ  | 
|             costMoneyList = PlayerControl.HaveMoneyEx(curPlayer, ShareDefine.TYPE_Price_Gold_Paper_Money, goldCallCost)  | 
|             if not costMoneyList:  | 
|                 return  | 
|               | 
|             infoDict = {"MapID":mapID, 'lineID':funcLineID, "Type":"Call"}  | 
|             for moneyType, moneyNum in costMoneyList:  | 
|                 PlayerControl.PayMoney(curPlayer, moneyType, moneyNum, ChConfig.Def_Cost_FBHelpBattle, infoDict)  | 
|         calledPlayerDict[calledPlayerID] = helpPlayerInfoDict.get("Relation", 0)  | 
|           | 
|     # Ö±½ÓÔÚµØÍ¼ÕÙ»½³öÀ´  | 
|     robotNPCID = IpyGameDataPY.GetFuncCfg("HelpBattleRobot", 1)  | 
|     posX, posY = curPlayer.GetPosX(), curPlayer.GetPosY()  | 
|     for calledPlayerID in calledPlayerDict.keys():  | 
|         if calledPlayerID not in helpBattlePlayerDict:  | 
|             continue  | 
|         helpPlayerInfoDict = helpBattlePlayerDict[calledPlayerID]  | 
|         job = helpPlayerInfoDict.get("Job", 1)  | 
|         if "FightPower" in helpPlayerInfoDict:  | 
|             fightPower = helpPlayerInfoDict["FightPower"]  | 
|             npcLV = helpPlayerInfoDict["LV"]  | 
|         else:  | 
|             fightPower = ipyData.GetRobotFightPower()  | 
|             npcLV = ipyData.GetRobotLV()  | 
|             calledPlayerDict.pop(calledPlayerID) # ÕÐNPC²»Í¨ÖªGameServer  | 
|               | 
|         jobSkillDict = ipyData.GetRobotSkillsDict()  | 
|           | 
|         position = GameMap.GetEmptyPlaceInAreaEx(posX, posY, 2, 6)  | 
|         npcPosX, npcPosY = position.GetPosX(), position.GetPosY()  | 
|         helpBattleNPC = NPCCommon.SummonMapNpc(robotNPCID, npcPosX, npcPosY)  | 
|         if not helpBattleNPC:  | 
|             continue  | 
|         objID = helpBattleNPC.GetID()  | 
|         helpBattleNPC.SetIsNeedProcess(True)  | 
|         GameWorld.Log("ÕÙ»½ÖúÕ½³É¹¦: calledPlayerID=%s,objID=%s,fightPower=%s" % (calledPlayerID, objID, fightPower), playerID)  | 
|         gameFB.SetGameFBDict(ChConfig.Def_FB_HelpBattleFBObjID % calledPlayerID, objID)  | 
|         helpBattleNPC.SetDict(ChConfig.Def_NPC_Dict_AtkDelayTick, calledCount * 1000) # °´×ª»»Ë³Ðòÿ¸öÑÓ³¤1Ãë¹¥»÷£¬·ÀÖ¹¶¯×÷Ò»Ö  | 
|         calledCount += 1  | 
|         # ÉèÖÃÖúÕ½ÊôÐÔ  | 
|         npcControl = NPCCommon.NPCControl(helpBattleNPC)  | 
|         npcControl.SetHelpBattleRobotRebornAttr(fightPower)  | 
|         __DoGiveHelpBattleRobotSkill(helpBattleNPC, jobSkillDict, job, npcLV)  | 
|           | 
|         # Í¨ÖªÇ°¶ËÕÙ»½³É¹¦  | 
|         callResultPack = ChPyNetSendPack.tagMCHelpBattleCallResult()  | 
|         callResultPack.ObjID = objID  | 
|         callResultPack.PlayerID = calledPlayerID  | 
|         callResultPack.Job = job  | 
|         NetPackCommon.SendFakePack(curPlayer, callResultPack)  | 
|           | 
|     # ÕÙ»½Âúºó  | 
|     if calledCount >= maxHelpPlayerCount:  | 
|         FBLogic.OnCallHelpBattleOK(curPlayer, tick)  | 
|           | 
|     # Í¨ÖªGameServer  | 
|     if calledPlayerDict:  | 
|         msgInfo = str(["Call", mapID, funcLineID, calledPlayerDict])  | 
|         GameWorld.GetPlayerManager().GameServer_QueryPlayerResult(curPlayer.GetID(), 0, 0, "FBHelpBattle", msgInfo, len(msgInfo))  | 
|         GameWorld.Log("GameServer_QueryPlayerResult: %s" % msgInfo, curPlayer.GetID())  | 
|     return  | 
|   | 
| def __DoGiveHelpBattleRobotSkill(curNPC, jobSkillDict, job, npcLV):  | 
|     skillManager = curNPC.GetSkillManager()  | 
|     if job not in jobSkillDict:  | 
|         return  | 
|     skillInfoDict = jobSkillDict[job]  | 
|     #{Ö°Òµ:{(¼¼ÄÜID,...):ËùÐèµÈ¼¶, ¼¼ÄÜID:ËùÐèµÈ¼¶, ...}, ...}  | 
|     #{1:{(12000, 12001, 12002, 12003):1, 12011:7, 12012:15, 12013:30, 12014:80, 12015:140}, 2:{(12100, 12101, 12102, 12103):1, 12111:7, 12112:15, 12114:80, 12115:140}}  | 
|     skillIDList = []  | 
|     for skillInfo, needLV in skillInfoDict.items():  | 
|         if npcLV < needLV:  | 
|             continue  | 
|         if isinstance(skillInfo, int):  | 
|             skillIDList.append(skillInfo)  | 
|         else:  | 
|             skillIDList += list(skillInfo)  | 
|     GameWorld.DebugLog("    ¸øÖúÕ½»úÆ÷È˼¼ÄÜ: job=%s,npcLV=%s, %s" % (job, npcLV, skillIDList))  | 
|     for skillID in skillIDList:  | 
|         skillManager.LearnSkillByID(skillID)  | 
|     return  | 
|   | 
| #// B1 07 ÖúսˢР#tagCMHelpBattleRefresh  | 
| #  | 
| #struct    tagCMHelpBattleRefresh  | 
| #{  | 
| #    tagHead         Head;  | 
| #};  | 
| def OnHelpBattleRefresh(index, clientData, tick):  | 
|     curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)  | 
|     SendGameServer_RefreshHelpBattlePlayer(curPlayer, isClientRefresh=True)  | 
|     return  | 
|   | 
| def SendGameServer_RefreshHelpBattlePlayer(curPlayer, mapID=0, funcLineID=0, isClientRefresh=False):  | 
|     ## ·¢ËÍGameServerÇëÇóË¢ÐÂÖúÕ½Íæ¼ÒÁÐ±í  | 
|     if not mapID:  | 
|         mapID = FBCommon.GetRecordMapID(curPlayer.GetMapID())  | 
|     if not funcLineID:  | 
|         funcLineID = FBCommon.GetFBPropertyMark()  | 
|     ipyData = IpyGameDataPY.GetIpyGameData("FBHelpBattle", mapID, funcLineID)  | 
|     if not ipyData:  | 
|         return  | 
|     playerID = curPlayer.GetPlayerID()  | 
|     gameFB = GameWorld.GetGameFB()  | 
|     costMoneyList = []  | 
|     calledPlayerIDDict = {} # ÒѾÕÙ»½µÄÍæ¼ÒID×Öµä {playerID:[ÊÇ·ñ¸¶·ÑÕÙ»½, Ö°Òµ], ...}  | 
|       | 
|     refreshCount = gameFB.GetPlayerGameFBDictByKey(playerID, ChConfig.FBPD_HelpBattleRefreshCount)  | 
|     if isClientRefresh:  | 
|         freeRefreshCount = IpyGameDataPY.GetFuncCfg("HelpBattleRefresh", 1)  | 
|         goldRefreshCount = IpyGameDataPY.GetFuncCfg("HelpBattleRefresh", 2)  | 
|         if refreshCount >= (freeRefreshCount + goldRefreshCount):  | 
|             GameWorld.DebugLog("³¬¹ýË¢ÐÂÖúÕ½Áбí´ÎÊý£¡ÎÞ·¨Ë¢ÐÂ!refreshCount=%s" % (refreshCount), playerID)  | 
|             return  | 
|           | 
|         if refreshCount >= freeRefreshCount:  | 
|             costGold = IpyGameDataPY.GetFuncCfg("HelpBattleRefresh", 3)  | 
|             costMoneyList = PlayerControl.HaveMoneyEx(curPlayer, ShareDefine.TYPE_Price_Gold_Paper_Money, costGold)  | 
|             if not costMoneyList:  | 
|                 GameWorld.DebugLog("»õ±Ò²»×ã!ÎÞ·¨Ë¢ÐÂÖúÕ½£¡")  | 
|                 return  | 
|               | 
|         # »ñÈ¡ÒѾÕÙ»½µÄÍæ¼Ò¾µÏñID  | 
|         helpBattlePlayerDict = PyGameData.g_fbHelpBattlePlayerDict.get(playerID, {})  | 
|         for helpPlayerID, helpPlayerInfoDict in helpBattlePlayerDict.items():  | 
|             objID = gameFB.GetGameFBDictByKey(ChConfig.Def_FB_HelpBattleFBObjID % helpPlayerID)  | 
|             if not objID:  | 
|                 continue  | 
|             needGoldCall = gameFB.GetGameFBDictByKey(ChConfig.Def_FB_HelpBattleGoldCall % helpPlayerID)  | 
|             job = helpPlayerInfoDict.get("Job", 1)  | 
|             relation = helpPlayerInfoDict.get("Relation", 0) # ¹ØÏµÐèÒÔË¢ÐÂÁбíʱµÄΪ׼£¬Èç¹ûÒѾÕÙ»½ÁË£¬ÔòÒѵ±Ê±µÄΪ׼  | 
|             calledPlayerIDDict[helpPlayerID] = [needGoldCall, job, relation]  | 
|               | 
|     # ·Ç¿Í»§¶ËˢеÄÊÓÎªÖØÐ¿ªÊ¼£¬ÖØÖÃˢдÎÊý   | 
|     else:  | 
|         if not refreshCount:  | 
|             gameFB.SetPlayerGameFBDict(playerID, ChConfig.FBPD_HelpBattleRefreshCount, 0)  | 
|         gameFB.SetGameFBDict(ChConfig.FBPD_HelpBattleFBFightPower, ipyData.GetFightPowerMin())  | 
|         gameFB.SetGameFBDict(ChConfig.FBPD_HelpBattleFBBaseHurt, ipyData.GetRobotBaseHurt())  | 
|         GameWorld.DebugLog("ÉèÖø±±¾Õ½Á¦=%s,±£µ×É˺¦=%s" % (ipyData.GetFightPowerMin(), ipyData.GetRobotBaseHurt()))  | 
|           | 
|     msgInfo = str(["Refresh", mapID, funcLineID, isClientRefresh, costMoneyList, calledPlayerIDDict])  | 
|     GameWorld.GetPlayerManager().GameServer_QueryPlayerResult(curPlayer.GetID(), 0, 0, "FBHelpBattle", msgInfo, len(msgInfo))  | 
|     GameWorld.Log("SendGameServer_RefreshHelpBattlePlayer %s" % (msgInfo), playerID)  | 
|     return  | 
|   | 
| def __OnHelpBattleRefreshResult(curPlayer, msgList, tick):  | 
|     ## Ë¢Ð·µ»Ø  | 
|     cmd, mapID, funcLineID, isClientRefresh, costMoneyList, calledPlayerIDDict, helpBattlePlayerDict = msgList  | 
|       | 
|     playerID = curPlayer.GetPlayerID()  | 
|     gameFB = GameWorld.GetGameFB()  | 
|       | 
|     # ¿ÛÇ®£¬¼ÓˢдÎÊý  | 
|     infoDict = {"MapID":mapID, 'lineID':funcLineID, "Type":"Refresh"}  | 
|     for moneyType, moneyNum in costMoneyList:  | 
|         PlayerControl.PayMoney(curPlayer, moneyType, moneyNum, ChConfig.Def_Cost_FBHelpBattle, infoDict)  | 
|     refreshCount = gameFB.GetPlayerGameFBDictByKey(playerID, ChConfig.FBPD_HelpBattleRefreshCount)  | 
|     if isClientRefresh:  | 
|         refreshCount += 1  | 
|         gameFB.SetPlayerGameFBDict(playerID, ChConfig.FBPD_HelpBattleRefreshCount, refreshCount)  | 
|           | 
|     GameWorld.Log("FBHelpBattleResult: %s,mapID=%s,funcLineID=%s,isClientRefresh=%s,costMoneyList=%s,calledPlayerIDDict=%s,refreshCount=%s"   | 
|                   % (cmd, mapID, funcLineID, isClientRefresh, costMoneyList, calledPlayerIDDict, refreshCount), playerID)  | 
|     GameWorld.Log("    helpBattlePlayerDict=%s" % (helpBattlePlayerDict), playerID)  | 
|     PyGameData.g_fbHelpBattlePlayerDict[playerID] = helpBattlePlayerDict  | 
|       | 
|     # Í¨ÖªÇ°¶Ë  | 
|     helpPlayerListPack = ChPyNetSendPack.tagMCHelpBattleList()  | 
|     helpPlayerListPack.RefreshCount = refreshCount  | 
|     helpPlayerListPack.HelpPlayerList = []  | 
|     for helpPlayerID, helpPlayerInfoDict in helpBattlePlayerDict.items():  | 
|         helpPlayer = ChPyNetSendPack.tagMCHelpBattlePlayer()  | 
|         helpPlayer.ObjID = gameFB.GetGameFBDictByKey(ChConfig.Def_FB_HelpBattleFBObjID % helpPlayerID) # »ñÈ¡ÒѾÕÙ»½µÄ¶ÔÓ¦objID  | 
|         helpPlayer.PlayerID = helpPlayerID  | 
|         helpPlayer.Job = helpPlayerInfoDict.get("Job", 1)  | 
|         # Íæ¼Ò¾µÏñ²ÅÓÐÃû×Ö£¬ÖúÕ½NPCÃû×Öǰ¶Ë´¦Àí  | 
|         if "Name" in helpPlayerInfoDict:  | 
|             helpPlayer.Name =  helpPlayerInfoDict["Name"]  | 
|             helpPlayer.NameLen =  len(helpPlayer.Name)  | 
|             helpPlayer.LV =  helpPlayerInfoDict["LV"]  | 
|             helpPlayer.RealmLV =  helpPlayerInfoDict["RealmLV"]  | 
|             helpPlayer.FightPower =  helpPlayerInfoDict["FightPower"]  | 
|             helpPlayer.Relation = helpPlayerInfoDict.get("Relation", 0)  | 
|             helpPlayer.IsNeedGold =  helpPlayerInfoDict.get("NeedGoldCall", 0)  | 
|         helpPlayerListPack.HelpPlayerList.append(helpPlayer)  | 
|     helpPlayerListPack.HelpCount = len(helpPlayerListPack.HelpPlayerList)  | 
|     NetPackCommon.SendFakePack(curPlayer, helpPlayerListPack)  | 
|     return  | 
|   | 
| def __OnHelpBattleRecord(curPlayer, msgList, tick):  | 
|     ## ÖúÕ½¼Ç¼ͬ²½  | 
|     cmd, helpRecordList, isLogin = msgList  | 
|     playerID = curPlayer.GetPlayerID()  | 
|     GameWorld.DebugLog("__OnHelpBattleRecord %s,helpRecordList=%s" % (cmd, helpRecordList), playerID)  | 
|       | 
|     addXianyuanCoinTotal = 0 # ÀÛ¼ÆÐèÒªÔö¼ÓµÄÏÉÔµ±Ò  | 
|     addXianyuanCoinTotalTotay = 0 # ÀÛ¼ÆÐèÒªÔö¼ÓµÄ½ñÈÕÏÉÔµ±Ò  | 
|     drList = []  | 
|       | 
|     totalHelpCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_HelpBattleTotalCount)  | 
|     recordPack = ChPyNetSendPack.tagMCHelpBattleRecordList()  | 
|     recordPack.RecordList = []  | 
|     for recordInfo in helpRecordList:  | 
|         callPlayerID, callPlayerName, mapID, funcLineID, xianyuanCoinAdd, relation, vipLV, recordTime = recordInfo  | 
|         timeStr = GameWorld.ChangeTimeNumToStr(recordTime)  | 
|         isSameDay = GameWorld.CheckTimeIsSameServerDayEx(recordTime)  | 
|           | 
|         record = ChPyNetSendPack.tagMCHelpBattleRecord()  | 
|         record.CallPlayerID = callPlayerID  | 
|         record.CallPlayerName = callPlayerName  | 
|         record.NameLen = len(record.CallPlayerName)  | 
|         record.MapID = mapID  | 
|         record.FuncLineID = funcLineID  | 
|         record.XianyuanCoinAdd = xianyuanCoinAdd  | 
|         record.Relation = relation  | 
|         record.VIPLV = vipLV  | 
|         record.HelpTime = timeStr  | 
|         recordPack.RecordList.append(record)  | 
|         drList.append({"CallPlayerID":callPlayerID, "MapID":mapID, "FuncLineID":funcLineID, "XianyuanCoinAdd":xianyuanCoinAdd,   | 
|                        "Relation":relation, "VIPLV":vipLV, "HelpTime":timeStr, "IsSameDay":isSameDay})  | 
|         addXianyuanCoinTotal += xianyuanCoinAdd  | 
|         if isSameDay:  | 
|             addXianyuanCoinTotalTotay += xianyuanCoinAdd  | 
|         totalHelpCount += 1  | 
|           | 
|     recordPack.RecordCount = len(recordPack.RecordList)  | 
|     NetPackCommon.SendFakePack(curPlayer, recordPack)  | 
|       | 
|     addDataDict = {"HelpList":drList}  | 
|     GameWorld.DebugLog("    addXianyuanCoinTotal=%s,addXianyuanCoinTotalTotay=%s,totalHelpCount=%s,isLogin=%s"   | 
|                        % (addXianyuanCoinTotal, addXianyuanCoinTotalTotay, totalHelpCount, isLogin), playerID)  | 
|     PlayerControl.GiveMoney(curPlayer, ShareDefine.TYPE_Price_XianyuanCoin, addXianyuanCoinTotal, addDataDict=addDataDict, isSysHint=False)  | 
|     if addXianyuanCoinTotalTotay:  | 
|         PlayerControl.AddTodayXianyuanCoin(curPlayer, addXianyuanCoinTotalTotay)  | 
|         if isLogin:  | 
|             curPlayer.SetDict(ChConfig.Def_PDict_TodayXianyuanCoinOnLogin, addXianyuanCoinTotalTotay)  | 
|             curPlayer.SetDict(ChConfig.Def_PDict_LoginAddTodayXianyuanCoinTime, int(time.time()))  | 
|             GameWorld.Log("    µÇ¼ʱ½ñÈÕÖúÕ½ÐÅÏ¢: addXianyuanCoinTotalTotay=%s" % (addXianyuanCoinTotalTotay), playerID)  | 
|               | 
|     # ¸üÐÂ×ÜÖúÕ½´ÎÊý£¬¸üÐÂÅÅÐаñ  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_HelpBattleTotalCount, totalHelpCount)  | 
|     if totalHelpCount >= IpyGameDataPY.GetFuncCfg("HelpBattleRefresh", 4):  | 
|         PlayerBillboard.UpdatePlayerBillboard(curPlayer, ShareDefine.Def_BT_FBHelpBattle, totalHelpCount)  | 
|     return  | 
|   | 
| def DoFBAddXianyuanCoin(curPlayer, mapID, lineID, isHelp=False):  | 
|     '''ÕæÈËÌôÕ½¸±±¾Ôö¼ÓÏÉÔµ±Ò£¬°üº¬¹ý¹Ø»òÖúÕ½£¨²»º¬¾µÏñÖúÕ½£©  | 
|     @param isHelp: ÊÇ·ñÖúÕ½µÄ  | 
|     @return: »ñµÃµÄÏÉÔµ±Ò, ÎÞ·¨»ñµÃÏÉÔµ±ÒÔÒò(1-´ïµ½ÖúÕ½´ÎÊýÉÏÏÞ£¬2-´ïµ½Ã¿ÈÕ»ñµÃÏÉÔµ±ÒÉÏÏÞ)  | 
|     '''  | 
|     playerID = curPlayer.GetPlayerID()  | 
|     fbFuncIpyData = IpyGameDataPY.GetIpyGameData("FBFunc", mapID)  | 
|     if not fbFuncIpyData:  | 
|         return 0, 0  | 
|       | 
|     reason = 0  | 
|     addCoinRate = 10000 # »ù´¡±¶ÂÊ  | 
|     if not isHelp:  | 
|         baseFBPoint = fbFuncIpyData.GetFBPoint() # ¹ý¹Ø - »ù´¡ÏÉÔµ±Ò  | 
|     else:  | 
|         baseFBPoint = fbFuncIpyData.GetHelpPoint() # ÖúÕ½  | 
|         dayHelpCountMax = fbFuncIpyData.GetDayHelpCountMax() # ÕæÊµÖúսÿÈÕ¿É»ñµÃÏÉÔµ±Ò´ÎÊý  | 
|         if dayHelpCountMax:  | 
|             todayHelpCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FBRealHelpCount % mapID)  | 
|             if todayHelpCount >= dayHelpCountMax:  | 
|                 baseFBPoint = 0  | 
|                 reason = 1  | 
|                 GameWorld.DebugLog("´ïµ½Ã¿ÈÕÖúÕ½¿É»ñµÃÏÉÔµ±Ò´ÎÊýÉÏÏÞ£¡ÎÞ·¨ÔÙ»ñµÃ!mapID=%s" % (mapID), playerID)  | 
|             else:  | 
|                 todayHelpCount += 1  | 
|                 PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FBRealHelpCount % mapID, todayHelpCount)  | 
|                 GameWorld.DebugLog("Ôö¼ÓÿÈÕÖúÕ½¿É»ñµÃÏÉÔµ±Ò´ÎÊý!mapID=%s,todayHelpCount=%s" % (mapID, todayHelpCount), playerID)  | 
|                   | 
|     xianyuanCoinUpper = IpyGameDataPY.GetFuncCfg("HelpBattlePoint", 1) # Ã¿ÈÕÏÉÔµ±ÒÉÏÏÞ  | 
|     relationCoinAddDict = IpyGameDataPY.GetFuncEvalCfg("HelpBattlePoint", 2, {}) # Éç½»¹ØÏµ¼Ó³É {"Éç½»¹ØÏµ":[¹ý¹Ø¼Ó³É, ÖúÕ½¼Ó³É], ...}   | 
|     todayXianyuanCoin = PlayerControl.GetTodayXianyuanCoin(curPlayer) # ½ñÈÕÒÑ»ñµÃÏÉÔµ±Ò  | 
|     playerXianyuanCoinUpper = xianyuanCoinUpper  | 
|     if curPlayer.GetVIPLv():  | 
|         playerXianyuanCoinUpper += PlayerVip.GetPrivilegeValue(curPlayer, ChConfig.VIPPrivilege_XianyuanCoinUpperAdd)  | 
|         addCoinRate += PlayerVip.GetPrivilegeValue(curPlayer, ChConfig.VIPPrivilege_XianyuanCoinAddPer)  | 
|           | 
|     #´ïµ½ÉÏÏÞÒ²ÐèÒª¼Ç¼£¬ËùÒÔÕâÀïÔݲ»ÏÞÖÆ  | 
|     #if todayXianyuanCoin >= playerXianyuanCoinUpper:  | 
|     #    GameWorld.DebugLog("Íæ¼Ò½ñÈÕÏÉÔµ±ÒÒÑ´ïÉÏÏÞ£¡todayXianyuanCoin=%s,playerXianyuanCoinUpper=%s"   | 
|     #                       % (todayXianyuanCoin, playerXianyuanCoinUpper), playerID)  | 
|     #    return  | 
|       | 
|     relation, relationAdd, relationPlayerID, relationPlayerName = 0, 0, 0, ""  | 
|       | 
|     fbType = GameWorld.GetMap().GetMapFBType()  | 
|     if fbType == IPY_GameWorld.fbtSingle:  | 
|         gameFB = GameWorld.GetGameFB()  | 
|         helpBattlePlayerDict = PyGameData.g_fbHelpBattlePlayerDict.get(playerID, {})  | 
|         for helpPlayerID, helpPlayerInfoDict in helpBattlePlayerDict.items():  | 
|             objID = gameFB.GetGameFBDictByKey(ChConfig.Def_FB_HelpBattleFBObjID % helpPlayerID)  | 
|             if not objID:  | 
|                 continue  | 
|             relation = helpPlayerInfoDict.get("Relation", 0)  | 
|             if not relation:  | 
|                 continue  | 
|             relationAddList = relationCoinAddDict.get(str(relation), [])  | 
|             relationAdd += relationAddList[0] if len(relationAddList) == 2 else 0  | 
|     elif fbType == IPY_GameWorld.fbtTeam:  | 
|         if playerID in PyGameData.g_teamFBMemRelationAddDict:  | 
|             relation, relationAdd, relationPlayerID, relationPlayerName = PyGameData.g_teamFBMemRelationAddDict.pop(playerID)  | 
|               | 
|     coinAdd = 0  | 
|     if baseFBPoint:  | 
|         coinAdd = int((baseFBPoint + relationAdd) * addCoinRate / 10000.0)  | 
|     canAddMax = max(playerXianyuanCoinUpper - todayXianyuanCoin, 0)  | 
|     coinAddReal = min(coinAdd, canAddMax) # Êµ¼Ê¼ÓÏÉÔµ±Ò  | 
|     if canAddMax == 0 and not reason:  | 
|         reason = 2  | 
|           | 
|     GameWorld.DebugLog("ÌôÕ½¸±±¾Ôö¼ÓÏÉÔµ±Ò: baseFBPoint=%s,relationAdd=%s,addCoinRate=%s,coinAdd=%s,canAddMax=%s,coinAddReal=%s,relationPlayerID=%s"   | 
|                        % (baseFBPoint, relationAdd, addCoinRate, coinAdd, canAddMax, coinAddReal, relationPlayerID), playerID)  | 
|     if coinAddReal:  | 
|         addDataDict = {"MapID":mapID, "FuncLineID":lineID}  | 
|         PlayerControl.GiveMoney(curPlayer, ShareDefine.TYPE_Price_XianyuanCoin, coinAddReal, addDataDict=addDataDict)  | 
|         PlayerControl.AddTodayXianyuanCoin(curPlayer, coinAddReal)  | 
|           | 
|     # Í¨Öª×Ô¼º»ñµÃÏÉÔµ±Ò  | 
|     msgPack = ChPyNetSendPack.tagMCAddXianyuanCoinMsg()  | 
|     msgPack.MapID = mapID  | 
|     msgPack.FuncLineID = lineID  | 
|     msgPack.Relation = relation  | 
|     msgPack.RelationCoinAdd = relationAdd  | 
|     msgPack.XianyuanCoinAdd = coinAddReal  | 
|     msgPack.Reason = reason  | 
|     msgPack.CallPlayerID = relationPlayerID  | 
|     msgPack.CallPlayerName = relationPlayerName  | 
|     msgPack.NameLen = len(msgPack.CallPlayerName)  | 
|     NetPackCommon.SendFakePack(curPlayer, msgPack)  | 
|     return coinAddReal, reason  | 
|   | 
| def __GetTeamFBMemRelationInfo(curPlayer, isHelp, leavePlayerID):  | 
|     ## ¼ÆËã¶ÓÔ±¼äÏ໥¼Ó³ÉÐÅÏ¢£¬ÀëÏßÍæ¼Ò²»Ëã  | 
|     relation = 0  | 
|     relationAdd = 0 # Éç½»¹ØÏµ¼Ó³É  | 
|     relationPlayerID = 0  | 
|     relationPlayerName = ""  | 
|     teamID = curPlayer.GetTeamID()  | 
|     if teamID not in PyGameData.g_teamFBMemRelationDict:  | 
|         return relation, relationAdd, relationPlayerID, relationPlayerName  | 
|       | 
|     playerManager = GameWorld.GetMapCopyPlayerManager()  | 
|     friendList, memFamilyIDDict, memNameDict = PyGameData.g_teamFBMemRelationDict[teamID]  | 
|     relationList = IpyGameDataPY.GetFuncEvalCfg("HelpBattlePoint", 3, []) # Éç½»¹ØÏµÓÅÏȼ¶  | 
|     relationCoinAddDict = IpyGameDataPY.GetFuncEvalCfg("HelpBattlePoint", 2, {}) # Éç½»¹ØÏµ¼Ó³É {"Éç½»¹ØÏµ":[¹ý¹Ø¼Ó³É, ÖúÕ½¼Ó³É], ...}   | 
|     playerID = curPlayer.GetPlayerID()  | 
|     familyID = curPlayer.GetFamilyID()  | 
|     if isHelp:  | 
|         # ÖúÕ½µÄËæ±ãȡһλÓÅÏȼ¶×î¸ßµÄ¼´¿É  | 
|         for memPlayerID, memFamilyID in memFamilyIDDict.items():  | 
|             memRelation, relationPlayerID = __GetTemMemRelation(playerManager, playerID, familyID, memPlayerID, memFamilyID, relationList, friendList, leavePlayerID)  | 
|             if not memRelation:  | 
|                 continue  | 
|             relation = memRelation  | 
|             relationAddList = relationCoinAddDict.get(str(memRelation), [])  | 
|             relationAdd += relationAddList[1] if len(relationAddList) == 2 else 0  | 
|             relationPlayerName = memNameDict[relationPlayerID]  | 
|             return relation, relationAdd, relationPlayerID, relationPlayerName  | 
|           | 
|     else:  | 
|         # ·ÇÖúÕ½ÏíÊÜËùÓжÓÔ±¼Ó³É  | 
|         for memPlayerID, memFamilyID in memFamilyIDDict.items():  | 
|             memRelation = __GetTemMemRelation(playerManager, playerID, familyID, memPlayerID, memFamilyID, relationList, friendList, leavePlayerID)[0]  | 
|             if not memRelation:  | 
|                 continue  | 
|             if memRelation == relationList[0]:  | 
|                 relation = memRelation  | 
|             elif relation:  | 
|                 relation = memRelation  | 
|             relationAddList = relationCoinAddDict.get(str(memRelation), [])  | 
|             relationAdd += relationAddList[0] if len(relationAddList) == 2 else 0  | 
|               | 
|     return relation, relationAdd, relationPlayerID, relationPlayerName  | 
|   | 
| def __GetTemMemRelation(playerManager, playerID, familyID, memPlayerID, memFamilyID, relationList, friendList, leavePlayerID):  | 
|     ## ÀëÏßÍæ¼Ò²»ËãÉç½»¹ØÏµ  | 
|     if leavePlayerID and memPlayerID == leavePlayerID:  | 
|         return 0, 0  | 
|     memPlayer = playerManager.FindPlayerByID(memPlayerID)  | 
|     if memPlayer == None or memPlayer.IsEmpty():  | 
|         return 0, 0  | 
|     for checkRelation in relationList:  | 
|         if checkRelation == 1:  | 
|             if [playerID, memPlayerID] in friendList:  | 
|                 return checkRelation, memPlayerID  | 
|         if checkRelation == 2:  | 
|             if playerID != memPlayerID and familyID and familyID == memFamilyID:  | 
|                 return checkRelation, memPlayerID              | 
|     return 0, 0  | 
|   | 
| def RefershTeamFBMemRelation(tick, leavePlayerID=0):  | 
|     ## Ë¢ÐÂ×é¶Ó¸±±¾¶ÓÔ±¹ØÏµ  | 
|     playerManager = GameWorld.GetMapCopyPlayerManager()  | 
|     for i in xrange(playerManager.GetPlayerCount()):  | 
|         player = playerManager.GetPlayerByIndex(i)  | 
|         if player == None or player.IsEmpty():  | 
|             continue  | 
|         if leavePlayerID and player.GetPlayerID() == leavePlayerID:  | 
|             PyGameData.g_teamFBMemRelationAddDict.pop(leavePlayerID, 0)  | 
|             continue  | 
|         relation, relationAdd, relationPlayerID, relationPlayerName = __GetTeamFBMemRelationInfo(player, FBCommon.GetIsHelpFight(player), leavePlayerID)  | 
|         PyGameData.g_teamFBMemRelationAddDict[player.GetPlayerID()] = [relation, relationAdd, relationPlayerID, relationPlayerName]  | 
|           | 
|     for index in xrange(playerManager.GetPlayerCount()):  | 
|         player = playerManager.GetPlayerByIndex(index)  | 
|         if player == None or player.IsEmpty():  | 
|             continue  | 
|         if leavePlayerID and player.GetPlayerID() == leavePlayerID:  | 
|             continue  | 
|         FBLogic.DoFBHelp(player, tick)  | 
|           | 
|     return  | 
|   | 
| def GetTeamFBMemRelationInfo(playerID):  | 
|     if playerID not in PyGameData.g_teamFBMemRelationAddDict:  | 
|         return 0, 0  | 
|     return PyGameData.g_teamFBMemRelationAddDict[playerID][:2]  | 
|   |