#!/usr/bin/python # -*- coding: GBK -*- #------------------------------------------------------------------------------- # ##@package PlayerFBHelpBattle # # @todo:¸±±¾Öúսϵͳ # @author hxp # @date 2018-11-24 # @version 1.0 # # ÏêϸÃèÊö: ¸±±¾Öúսϵͳ # #------------------------------------------------------------------------------- #"""Version = 2018-11-24 22:30""" #------------------------------------------------------------------------------- import PlayerFriend import IpyGameDataPY import PlayerViewCache import IPY_GameServer import PlayerAssist import ShareDefine import PyGameData import GameWorld import ChConfig import random import time MaxRobotID = 100 # ×î´ó»úÆ÷ÈËNPC¶¨ÒåID Def_RecType_CheckInPlayer = ShareDefine.Def_UniversalGameRecType_FBHelpBattleCheckInPlayer ## ÖúÕ½Íæ¼Ò¼òÒªÐÅÏ¢ class HelpBattlePlayer(): def __init__(self, playerID): self.playerID = playerID self.job = 0 self.face = 0 self.facePic = 0 self.playerName = "" self.playerLV = 0 self.realmLV = 0 self.fightPower = 0 self.familyID = 0 self.vipLV = 0 self.checkInCount = 0 # ÀۼƵǼǴÎÊý self.checkInTime = 0 self.todayHelpCountDict = {} # ½ñÌìÒÑÖúÕ½´ÎÊý {(mapID, lineID):count, ...}, ͨÓôÎÊýʱlineIDĬÈÏΪ0 self.getThanksGiftCountDict = {} # ЭÖú·½½ñÈÕ½ÓÊոøÐлÀñºÐ´ÎÊý {itemID:count, ...} return def OnServerStart(): GameWorld.Log("¿ª·þ¼ÓÔØÖúÕ½Ïà¹ØÐÅÏ¢...") universalRecMgr = GameWorld.GetUniversalRecMgr() checkInPlayerRecList = universalRecMgr.GetTypeList(Def_RecType_CheckInPlayer) for index in xrange(checkInPlayerRecList.Count()): recData = checkInPlayerRecList.At(index) playerID = recData.GetValue1() helpBattlePlayer = HelpBattlePlayer(playerID) helpBattlePlayer.checkInTime = recData.GetTime() helpBattlePlayer.fightPower = recData.GetValue2() helpBattlePlayer.familyID = recData.GetValue3() helpBattlePlayer.checkInCount = recData.GetValue4() value5 = recData.GetValue5() helpBattlePlayer.playerLV = value5 / 100000 helpBattlePlayer.vipLV = int(str(value5)[-5:-3]) helpBattlePlayer.realmLV = int(str(value5)[-3:-1]) helpBattlePlayer.job = value5 % 10 helpBattlePlayer.playerName = recData.GetStrValue1() strValue2 = recData.GetStrValue2() strValue2List = strValue2.split("|") helpBattlePlayer.face = GameWorld.ToIntDef(strValue2List[0] if len(strValue2List) > 0 else "0", 0) helpBattlePlayer.facePic = GameWorld.ToIntDef(strValue2List[1] if len(strValue2List) > 1 else "0", 0) strValue3 = recData.GetStrValue3() strValue3List = strValue3.split("|") helpCountDictStr = strValue3List[0] if len(strValue3List) > 0 else "{}" getThanksGiftCountDictStr = strValue3List[1] if len(strValue3List) > 1 else "{}" if helpCountDictStr.startswith("{") and helpCountDictStr.endswith("}"): helpBattlePlayer.todayHelpCountDict = eval(helpCountDictStr) else: GameWorld.ErrLog("LoadCheckInPlayerError: helpCountDictStr=%s" % helpCountDictStr, playerID) if getThanksGiftCountDictStr.startswith("{") and getThanksGiftCountDictStr.endswith("}"): helpBattlePlayer.getThanksGiftCountDict = eval(getThanksGiftCountDictStr) else: GameWorld.ErrLog("LoadCheckInPlayerError: getThanksGiftCountDictStr=%s" % getThanksGiftCountDictStr, playerID) PyGameData.g_fbHelpBattleCheckInPlayerDict[playerID] = helpBattlePlayer GameWorld.Log("¼ÓÔØÖúÕ½µÇ¼ÇÍæ¼Ò¼Ç¼: %s" % len(PyGameData.g_fbHelpBattleCheckInPlayerDict)) return def OnServerClose(): GameWorld.Log("¹Ø·þ±£´æÖúÕ½Ïà¹ØÐÅÏ¢...") universalRecMgr = GameWorld.GetUniversalRecMgr() universalRecMgr.Delete(Def_RecType_CheckInPlayer) GameWorld.Log("±£´æÖúÕ½µÇ¼ÇÍæ¼Ò¼Ç¼: %s" % len(PyGameData.g_fbHelpBattleCheckInPlayerDict)) checkInPlayerRecList = universalRecMgr.GetTypeList(Def_RecType_CheckInPlayer) for playerID, checkInPlayer in PyGameData.g_fbHelpBattleCheckInPlayerDict.items(): recData = checkInPlayerRecList.AddRec() recData.SetTime(checkInPlayer.checkInTime) recData.SetValue1(playerID) recData.SetValue2(min(max(checkInPlayer.fightPower, 0), ChConfig.Def_UpperLimit_DWord)) recData.SetValue3(checkInPlayer.familyID) recData.SetValue4(checkInPlayer.checkInCount) recData.SetValue5(int("%d%02d%02d%d" % (checkInPlayer.playerLV, checkInPlayer.vipLV, checkInPlayer.realmLV, checkInPlayer.job))) recData.SetStrValue1(checkInPlayer.playerName) recData.SetStrValue2("%s|%s" % (checkInPlayer.face, checkInPlayer.facePic)) strValue3 = "%s|%s" % (str(checkInPlayer.todayHelpCountDict).replace(" ", ""), str(checkInPlayer.getThanksGiftCountDict).replace(" ", "")) recData.SetStrValue3(strValue3) return def HelpBattleOnDay(): curTime = int(time.time()) checkInValidHours = IpyGameDataPY.GetFuncCfg("HelpBattleCheckIn", 1) # µÇ¼ÇÓÐЧʱ³¤£¬Ð¡Ê± # ÕâÀïÑÓ³¤30·ÖÖÓÇå³ý£¬·ÀÖ¹ÒѾ­±»ÕÙ»½»¹Ã»½áËãµÄµ¼ÖÂÕÒ²»µ½µÇ¼ÇÐÅÏ¢ checkInValidSeconds = checkInValidHours * 3600 + 30 * 60 # Ç峬ʱµÇ¼Ç£¬ÖØÖÃÐÅÏ¢ for playerID, checkInPlayer in PyGameData.g_fbHelpBattleCheckInPlayerDict.items(): checkInTime = checkInPlayer.checkInTime if curTime - checkInTime > checkInValidSeconds: PyGameData.g_fbHelpBattleCheckInPlayerDict.pop(playerID) GameWorld.Log("Çå³ý³¬Ê±ÖúÕ½µÇ¼ÇÍæ¼Ò: curTime=%s,checkInTime=%s" % (curTime, checkInTime), playerID) continue checkInPlayer.todayHelpCountDict = {} checkInPlayer.getThanksGiftCountDict = {} return ## ÊÇ·ñÔÚÖúÕ½µÇ¼ÇÁбíÀï def IsInHelpBattleCheckInList(playerID): return playerID in PyGameData.g_fbHelpBattleCheckInPlayerDict def MapServer_FBHelpBattle(curPlayer, msgList): ## µØÍ¼Íæ¼ÒÇëÇóÖúÕ½Ïà¹Ø²Ù×÷ GameWorld.DebugLog("MapServer_FBHelpBattle %s" % str(msgList), curPlayer.GetPlayerID()) if not msgList: return "" cmd = msgList[0] result = [] # µÇ¼Ç if cmd == "CheckIn": result = __DoPlayerFBHelpBattleCheckIn(curPlayer, msgList) # Ë¢ÐÂÖúÕ½Áбí elif cmd == "Refresh": result = __DoFBHelpBattleRefresh(curPlayer, msgList) # ÕÙ»½ elif cmd == "Call": result = __DoFBHelpBattleCall(curPlayer.GetPlayerID(), curPlayer.GetName(), msgList) # ɨµ´ÕÙ»½ elif cmd == "SweepCall": result = __DoFBHelpBattleSweepCall(curPlayer, msgList) # ЭÖúÍê³É elif cmd == "AssistFinish": __DoAssistFinish(curPlayer, msgList) return if result == None: return return msgList + result def __DoPlayerFBHelpBattleCheckIn(curPlayer, msgList): ## Íæ¼ÒµÇ¼Ç checkInCount, fightPower = msgList[1:] fightPower = min(fightPower, ChConfig.Def_UpperLimit_DWord) # µÇ¼ÇÖúÕ½Õ½Á¦×î¸ßÔÝÖ§³Ö20E curTime = int(time.time()) playerID = curPlayer.GetPlayerID() curCache = PlayerViewCache.FindViewCache(playerID) haveViewCache = 1 if curCache else 0 helpBattlePlayer = PyGameData.g_fbHelpBattleCheckInPlayerDict.get(playerID) if not helpBattlePlayer: helpBattlePlayer = HelpBattlePlayer(playerID) PyGameData.g_fbHelpBattleCheckInPlayerDict[playerID] = helpBattlePlayer helpBattlePlayer.playerName = curPlayer.GetName() helpBattlePlayer.playerLV = curPlayer.GetLV() helpBattlePlayer.job = curPlayer.GetJob() helpBattlePlayer.face = curPlayer.GetFace() helpBattlePlayer.facePic = curPlayer.GetFacePic() helpBattlePlayer.realmLV = curPlayer.GetOfficialRank() helpBattlePlayer.fightPower = fightPower helpBattlePlayer.familyID = curPlayer.GetFamilyID() helpBattlePlayer.vipLV = curPlayer.GetVIPLv() helpBattlePlayer.checkInCount = checkInCount + 1 helpBattlePlayer.checkInTime = curTime isOK = 1 # ĬÈϳɹ¦ GameWorld.Log("Íæ¼ÒÖúÕ½µÇ¼Ç: playerLV=%s,fightPower=%s,familyID=%s,vipLV=%s,checkInCount=%s,haveViewCache=%s" % (curPlayer.GetLV(), fightPower, curPlayer.GetFamilyID(), curPlayer.GetVIPLv(), checkInCount + 1, haveViewCache), playerID) return [isOK, haveViewCache] def UpdateCheckInPlayerInfo(playerID, fightPower, familyID, playerName): ## ¸üеǼǵÄÖúÕ½Íæ¼ÒµÈ¼¶Õ½Á¦ if playerID not in PyGameData.g_fbHelpBattleCheckInPlayerDict: return fightPower = min(fightPower, ChConfig.Def_UpperLimit_DWord) # µÇ¼ÇÖúÕ½Õ½Á¦×î¸ßÔÝÖ§³Ö20E helpBattlePlayer = PyGameData.g_fbHelpBattleCheckInPlayerDict[playerID] helpBattlePlayer.fightPower = fightPower helpBattlePlayer.familyID = familyID helpBattlePlayer.playerName = playerName GameWorld.DebugLog("¸üÐÂÖúÕ½Íæ¼ÒµÈ¼¶Õ½Á¦: fightPower=%s,familyID=%s" % (fightPower, familyID), playerID) return def UpdateCheckInPlayerInfoByRefresh(curPlayer, refreshType, value): ## ¸üеǼǵÄÖúÕ½Íæ¼ÒÏÉÃËID playerID = curPlayer.GetPlayerID() if playerID not in PyGameData.g_fbHelpBattleCheckInPlayerDict: return helpBattlePlayer = PyGameData.g_fbHelpBattleCheckInPlayerDict[playerID] if refreshType == IPY_GameServer.CDBPlayerRefresh_LV: helpBattlePlayer.playerLV = value elif refreshType == IPY_GameServer.CDBPlayerRefresh_VIPLv: helpBattlePlayer.vipLV = value elif refreshType == IPY_GameServer.CDBPlayerRefresh_Face: helpBattlePlayer.face = value elif refreshType == IPY_GameServer.CDBPlayerRefresh_HairColor: helpBattlePlayer.facePic = value else: return GameWorld.DebugLog("¸üÐÂÖúÕ½Íæ¼ÒÐÅÏ¢: refreshType=%s,value=%s" % (refreshType, value), playerID) return def __DoFBHelpBattleRefresh(curPlayer, msgList): ## ÖúÕ½ÁбíˢРmapID, funcLineID, isClientRefresh, costMoneyList, calledPlayerIDDict = msgList[1:] helpBattlePlayerDict = {} # ͬ²½¸øµØÍ¼·þÎñÆ÷µÄ´ýÑ¡ÖúÕ½Íæ¼ÒÁбíÐÅÏ¢ ipyData = IpyGameDataPY.GetIpyGameData("FBHelpBattle", mapID, funcLineID) if not ipyData: return [helpBattlePlayerDict] fightPowerMin = ipyData.GetFightPowerMin() fightPowerMax = ipyData.GetFightPowerMax() limitLV = ipyData.GetLVLimit() dayFreeHelpCountInfo = ipyData.GetDayFreeHelpCount() # ÿÈÕÃâ·ÑÖúÕ½´ÎÊý£¬[ÿÈÕÃâ·ÑÖúÕ½´ÎÊý, ÊÇ·ñËùÓвãͨÓÃ] dayFreeHelpCount = 0 # 0ΪÎÞÏÞÖÆ´ÎÊý helpCountLineID = funcLineID # ÖúÕ½´ÎÊýËùÊôlineID£¬µ±ËùÓвãͨÓÃʱ£¬Ä¬ÈÏΪ0 if dayFreeHelpCountInfo and len(dayFreeHelpCountInfo) == 2: dayFreeHelpCount, isAllLineCount = dayFreeHelpCountInfo if isAllLineCount: helpCountLineID = 0 helpCountKey = (mapID, helpCountLineID) playerID = curPlayer.GetPlayerID() GameWorld.Log("Ë¢ÐÂÖúÕ½Áбí: mapID=%s,funcLineID=%s,helpCountLineID=%s,isClientRefresh=%s,costMoneyList=%s,calledPlayerIDDict=%s" % (mapID, funcLineID, helpCountLineID, isClientRefresh, costMoneyList, calledPlayerIDDict), playerID) onlyFree = False goldCallCount = 0 nowFreeRelationCount, nowRelationCount, nowRobotCount = 0, 0, 0 atleastFreeRelationCount = IpyGameDataPY.GetFuncCfg("HelpBattleCall2", 1) # ÖÁÉÙÃâ·ÑÉç½»ÈËÊý£¬ÎÞÉç½»ÔòºöÂÔ atleastRelationCount = IpyGameDataPY.GetFuncCfg("HelpBattleCall2", 2) # ÖÁÉÙÉç½»ÈËÊý£¬ÎÞÉç½»ÔòºöÂÔ£¨ÈËÊý°üº¬Ãâ·ÑÉç½»ÈËÊý£© atmostRobotCount = IpyGameDataPY.GetFuncCfg("HelpBattleCall2", 3) # ÖúÕ½Áбí»úÆ÷ÈËÖÁ¶àÊýÁ¿ allowNoRelation = IpyGameDataPY.GetFuncCfg("HelpBattleCall2", 4) # ÖúÕ½ÁбíÊÇ·ñ³öÏÖ·ÇÉç½»¹ØÏµÍæ¼Ò GameWorld.DebugLog(" atleastFreeRelationCount=%s,atleastRelationCount=%s" % (atleastFreeRelationCount, atleastRelationCount)) #ÒѾ­ÕÙ»½µÄ±£Áô for calledPlayerID, callInfo in calledPlayerIDDict.items(): needGoldCall, job, relation = callInfo # Íæ¼Ò¾µÏñ if calledPlayerID in PyGameData.g_fbHelpBattleCheckInPlayerDict: helpBattlePlayer = PyGameData.g_fbHelpBattleCheckInPlayerDict[calledPlayerID] helpBattlePlayerDict[calledPlayerID] = __GetNotifyMapServerHelpPlayerInfoDict(helpBattlePlayer, needGoldCall, job, relation) if needGoldCall: goldCallCount += 1 if relation: nowRelationCount += 1 if not needGoldCall: nowFreeRelationCount += 1 # »úÆ÷ÈËNPC elif 1 <= calledPlayerID <= MaxRobotID: nowRobotCount += 1 helpBattlePlayerDict[calledPlayerID] = __GetNotifyMapServerHelpPlayerInfoDict(None, False, job) else: GameWorld.ErrLog("ÒÑÕÙ»½µÄÖúÕ½Íæ¼ÒÕÒ²»µ½¾µÏñ»º´æ£¡ÀíÂÛÉϲ»´æÔÚ¸ÃÇé¿ö£¬¾µÏñ»º´æÊÍ·Å»á±ÈµÇ¼ÇÓÐЧʱ³¤¶à°ëСʱ£¡") continue if helpBattlePlayerDict: GameWorld.Log("ÒÑÕÙ»½µÄÖúÕ½: %s" % str(helpBattlePlayerDict), playerID) curTime = int(time.time()) maxHelpPlayerSelectCount = IpyGameDataPY.GetFuncCfg("HelpBattleCall", 1) # ×î´ó¿ÉÒÔÑ¡ÔñÖúÕ½µÄÍæ¼Ò¸öÊý maxGoldHelpPlayerCount = IpyGameDataPY.GetFuncCfg("HelpBattleCall", 3) # ×î´ó¸¶·ÑÕÙ»½ÈËÊý checkInValidHours = IpyGameDataPY.GetFuncCfg("HelpBattleCheckIn", 1) # µÇ¼ÇÓÐЧʱ³¤£¬Ð¡Ê± checkInValidSeconds = checkInValidHours * 3600 checkInPlayerIDList = PyGameData.g_fbHelpBattleCheckInPlayerDict.keys() random.shuffle(checkInPlayerIDList) GameWorld.Log(" µÇ¼ÇÖúÕ½ÈËÊý=%s" % (len(checkInPlayerIDList)), playerID) if not allowNoRelation: atleastRelationCount = maxHelpPlayerSelectCount GameWorld.DebugLog("²»ÔÊÐí³öÏÖ·ÇÉç½»ÈËÊý£¬Ä¬ÈÏÉèÖÃÖÁÉÙÉç½»ÈËÊýΪ×î´ó¿ÉÑ¡ÔñÈËÊý! %s" % atleastRelationCount) # 1. ÖÁÉÙÉç½»¹ØÏµÈËÊý»¹²»×ãµÄ£¬ÏÈ´¦ÀíÖÁÉÙÉç½»¹ØÏµÈËÊý if nowRelationCount < atleastRelationCount: relationIDList = [] friendIDList = PlayerFriend.GetFriendStruct(playerID).GetSocialIDList() relationIDList += friendIDList #GameWorld.DebugLog(" ºÃÓÑIDÁбí, friendIDList=%s" % friendIDList, playerID) curFamily = curPlayer.GetFamily() familyMemList = [] if curFamily: for index in xrange(curFamily.GetCount()): member = curFamily.GetAt(index) memberID = member.GetPlayerID() familyMemList.append(memberID) if memberID != playerID and memberID not in relationIDList: relationIDList.append(memberID) #GameWorld.DebugLog(" ÃËÓÑIDÁбí, familyMemList=%s" % familyMemList, playerID) random.shuffle(relationIDList) #GameWorld.DebugLog(" ÓÐÉç½»µÄIDÁбí, relationIDList=%s" % relationIDList, playerID) tempRelationHelpPlayerList = [] for relationID in relationIDList: if nowRelationCount >= atleastRelationCount: break if relationID not in checkInPlayerIDList: continue helpBattlePlayer = PyGameData.g_fbHelpBattleCheckInPlayerDict[relationID] canHelp, needGoldCall = __CheckCanHelpComm(playerID, helpBattlePlayerDict, relationID, helpBattlePlayer, limitLV, fightPowerMin, fightPowerMax, checkInValidSeconds, curTime, helpCountKey, dayFreeHelpCount, onlyFree, goldCallCount, maxGoldHelpPlayerCount) if not canHelp: continue # Ãâ·ÑÉç½»ÈËÊý²»×ãÇÒÃâ·Ñ or Ãâ·ÑÉç½»ÈËÊý¹»ÁËÇÒ×ÜÉç½»ÈËÊý»¹²»¹» ; ¶¼Ö±½Ó¼ÓÈëÖúÕ½Áбí if (nowFreeRelationCount < atleastFreeRelationCount and not needGoldCall) \ or (nowFreeRelationCount >= atleastFreeRelationCount and nowRelationCount < atleastRelationCount): goldCallCount, nowRelationCount, nowFreeRelationCount = \ __AddHelpPlayer(curPlayer, helpBattlePlayer, helpBattlePlayerDict, needGoldCall, goldCallCount, nowRelationCount, nowFreeRelationCount) else: lackRelationCount = atleastRelationCount - nowRelationCount if len(tempRelationHelpPlayerList) < lackRelationCount: tempRelationHelpPlayerList.append([helpBattlePlayer, needGoldCall]) lackRelationCount = atleastRelationCount - nowRelationCount if lackRelationCount > 0: for helpBattlePlayer, needGoldCall in tempRelationHelpPlayerList[:lackRelationCount]: goldCallCount, nowRelationCount, nowFreeRelationCount = \ __AddHelpPlayer(curPlayer, helpBattlePlayer, helpBattlePlayerDict, needGoldCall, goldCallCount, nowRelationCount, nowFreeRelationCount) # 2. ³£¹æÌí¼ÓÖúÕ½ÈËÊý if allowNoRelation: for checkInPlayerID in checkInPlayerIDList: if len(helpBattlePlayerDict) >= maxHelpPlayerSelectCount: GameWorld.DebugLog(" ³¬¹ý×î´ó¸öÊýÁ˲»´¦Àí, checkInPlayerID=%s" % checkInPlayerID) break helpBattlePlayer = PyGameData.g_fbHelpBattleCheckInPlayerDict[checkInPlayerID] canHelp, needGoldCall = __CheckCanHelpComm(playerID, helpBattlePlayerDict, checkInPlayerID, helpBattlePlayer, limitLV, fightPowerMin, fightPowerMax, checkInValidSeconds, curTime, helpCountKey, dayFreeHelpCount, onlyFree, goldCallCount, maxGoldHelpPlayerCount) if not canHelp: continue goldCallCount, nowRelationCount, nowFreeRelationCount = \ __AddHelpPlayer(curPlayer, helpBattlePlayer, helpBattlePlayerDict, needGoldCall, goldCallCount, nowRelationCount, nowFreeRelationCount) # 3. ²»×ãµÄ»úÆ÷ÈËNPC²¹×ã openJobList = IpyGameDataPY.GetFuncEvalCfg("OpenJob", 1) # ¿ª·ÅµÄÖ°Òµ lackCount = maxHelpPlayerSelectCount - len(helpBattlePlayerDict) robotID = 0 # »úÆ÷ÈËNPC¶¨ÒåID´Ó1¿ªÊ¼ while lackCount > 0 and robotID < MaxRobotID and nowRobotCount < atmostRobotCount: robotID += 1 if robotID in helpBattlePlayerDict: continue lackCount -= 1 nowRobotCount += 1 randJob = random.choice(openJobList) helpBattlePlayerDict[robotID] = __GetNotifyMapServerHelpPlayerInfoDict(None, False, randJob) GameWorld.Log(" helpBattlePlayerDict=%s" % (helpBattlePlayerDict), playerID) return [helpBattlePlayerDict] def __CheckCanHelpComm(playerID, helpBattlePlayerDict, checkInPlayerID, helpBattlePlayer, limitLV, fightPowerMin, fightPowerMax, checkInValidSeconds, curTime, helpCountKey, dayFreeHelpCount, onlyFree=False, goldCallCount=0, maxGoldHelpPlayerCount=0): ## ³£¹æ¼ì²éÊÇ·ñÂú×ãÖúÕ½Ìõ¼þ if checkInPlayerID == playerID: GameWorld.DebugLog(" ×Ô¼º²»´¦Àí, checkInPlayerID=%s" % checkInPlayerID) return False, False if checkInPlayerID in helpBattlePlayerDict: GameWorld.DebugLog(" ÒѾ­ÔÚÖúÕ½ÀïµÄ²»´¦Àí, checkInPlayerID=%s" % checkInPlayerID) return False, False checkInPlayerLV = helpBattlePlayer.playerLV checkInPlayerFightPower = helpBattlePlayer.fightPower checkInTime = helpBattlePlayer.checkInTime if checkInPlayerLV < limitLV: GameWorld.DebugLog(" µÈ¼¶²»×ã, checkInPlayerID=%s,checkInPlayerLV=%s < limitLV=%s" % (checkInPlayerID, checkInPlayerLV, limitLV)) return False, False if fightPowerMin and checkInPlayerFightPower < fightPowerMin: GameWorld.DebugLog(" Õ½Á¦²»×ã, checkInPlayerID=%s,checkInPlayerFightPower=%s < fightPowerMin=%s" % (checkInPlayerID, checkInPlayerFightPower, fightPowerMin)) return False, False if fightPowerMax and checkInPlayerFightPower > fightPowerMax: GameWorld.DebugLog(" Õ½Á¦³¬³ö, checkInPlayerID=%s,checkInPlayerFightPower=%s > fightPowerMax=%s" % (checkInPlayerID, checkInPlayerFightPower, fightPowerMax)) return False, False passTime = curTime - checkInTime if passTime > checkInValidSeconds: GameWorld.DebugLog(" µÇ¼Ç³¬Ê±, checkInPlayerID=%s,checkInTime=%s,passTime=%s > checkInValidSeconds=%s" % (checkInPlayerID, checkInTime, passTime, checkInValidSeconds)) return False, False todayHelpCount = helpBattlePlayer.todayHelpCountDict.get(helpCountKey, 0) needGoldCall = dayFreeHelpCount and todayHelpCount >= dayFreeHelpCount if needGoldCall: if onlyFree: GameWorld.DebugLog(" ²»ÊÇÃâ·Ñ, checkInPlayerID=%s,todayHelpCount=%s > dayFreeHelpCount=%s" % (checkInPlayerID, todayHelpCount, dayFreeHelpCount)) return False, needGoldCall if goldCallCount >= maxGoldHelpPlayerCount: GameWorld.DebugLog(" ³¬¹ý×î´ó¸¶·ÑÕÙ»½ÈËÊý, checkInPlayerID=%s,goldCallCount=%s > maxGoldHelpPlayerCount=%s" % (checkInPlayerID, goldCallCount, maxGoldHelpPlayerCount)) return False, needGoldCall return True, needGoldCall def __AddHelpPlayer(curPlayer, helpBattlePlayer, helpBattlePlayerDict, needGoldCall, goldCallCount, nowRelationCount, nowFreeRelationCount): ## Ìí¼ÓÖúÕ½Íæ¼Òµ½ÖúÕ½Áбí if needGoldCall: goldCallCount += 1 relation = __GetHelpBattleRelation(curPlayer, helpBattlePlayer) if relation: nowRelationCount += 1 if not needGoldCall: nowFreeRelationCount += 1 helpPlayerID = helpBattlePlayer.playerID helpBattlePlayerDict[helpPlayerID] = __GetNotifyMapServerHelpPlayerInfoDict(helpBattlePlayer, needGoldCall, helpBattlePlayer.job, relation) GameWorld.DebugLog(" ÖúÕ½ÁбíÌí¼ÓÍæ¼Ò: helpPlayerID=%s,needGoldCall=%s,relation=%s,goldCallCount=%s,nowRelationCount=%s,nowFreeRelationCount=%s" % (helpPlayerID, needGoldCall, relation, goldCallCount, nowRelationCount, nowFreeRelationCount)) return goldCallCount, nowRelationCount, nowFreeRelationCount def __GetHelpBattleRelation(curPlayer, helpBattlePlayer): ## »ñÈ¡ÖúÕ½Éç½»¹ØÏµ 0-ÎÞ£¬1-ºÃÓÑ£¬2-ÃËÓÑ if not helpBattlePlayer: return 0 playerID = curPlayer.GetPlayerID() tagPlayerID = helpBattlePlayer.playerID tagFamilyID = helpBattlePlayer.familyID relationList = IpyGameDataPY.GetFuncEvalCfg("HelpBattlePoint", 3, []) # Éç½»¹ØÏµÓÅÏȼ¶ for checkRelation in relationList: if checkRelation == 1: if PlayerFriend.IsFriend(playerID, tagPlayerID): return checkRelation if checkRelation == 2: if tagFamilyID and curPlayer.GetFamilyID() == tagFamilyID: return checkRelation return 0 def __GetNotifyMapServerHelpPlayerInfoDict(helpBattlePlayer, needGoldCall, job, relation=0): ## »ñȡͬ²½¸øµØÍ¼µÄÖúÕ½Íæ¼Ò¼òÒªÐÅÏ¢ helpPlayerDict = {"Job":job} if not helpBattlePlayer: return helpPlayerDict if needGoldCall: helpPlayerDict["NeedGoldCall"] = 1 helpPlayerDict["Name"] = helpBattlePlayer.playerName helpPlayerDict["LV"] = helpBattlePlayer.playerLV #helpPlayerDict["Job"] = helpBattlePlayer.job helpPlayerDict["Face"] = helpBattlePlayer.face helpPlayerDict["FacePic"] = helpBattlePlayer.facePic helpPlayerDict["RealmLV"] = helpBattlePlayer.realmLV helpPlayerDict["FightPower"] = helpBattlePlayer.fightPower helpPlayerDict["Relation"] = relation return helpPlayerDict def __DoFBHelpBattleSweepCall(curPlayer, msgList): ''' ɨµ´ÖúÕ½ÁбíË¢ÐÂÇÒÖ±½ÓÕÙ»½ Ëæ»úÑ¡ÔñÃâ·ÑµÄÍæ¼Ò ''' mapID, funcLineID = msgList[1:] helpBattlePlayerDict = {} # ͬ²½¸øµØÍ¼·þÎñÆ÷µÄ´ýÑ¡ÖúÕ½Íæ¼ÒÁбíÐÅÏ¢ fbFuncIpyData = IpyGameDataPY.GetIpyGameData("FBFunc", mapID) fbHelpIpyData = IpyGameDataPY.GetIpyGameData("FBHelpBattle", mapID, funcLineID) if not fbFuncIpyData or not fbHelpIpyData: return [helpBattlePlayerDict] fightPowerMin = fbHelpIpyData.GetFightPowerMin() fightPowerMax = 0#fbHelpIpyData.GetFightPowerMax() # ɨµ´Ôݲ»ÏÞÖÆ×î¸ßÕ½Á¦ limitLV = fbHelpIpyData.GetLVLimit() dayFreeHelpCountInfo = fbHelpIpyData.GetDayFreeHelpCount() # ÿÈÕÃâ·ÑÖúÕ½´ÎÊý£¬[ÿÈÕÃâ·ÑÖúÕ½´ÎÊý, ÊÇ·ñËùÓвãͨÓÃ] dayFreeHelpCount = 0 # 0ΪÎÞÏÞÖÆ´ÎÊý helpCountLineID = funcLineID # ÖúÕ½´ÎÊýËùÊôlineID£¬µ±ËùÓвãͨÓÃʱ£¬Ä¬ÈÏΪ0 if dayFreeHelpCountInfo and len(dayFreeHelpCountInfo) == 2: dayFreeHelpCount, isAllLineCount = dayFreeHelpCountInfo if isAllLineCount: helpCountLineID = 0 helpCountKey = (mapID, helpCountLineID) playerID = curPlayer.GetPlayerID() GameWorld.Log("ɨµ´Ë¢ÐÂÖúÕ½Áбí: mapID=%s,funcLineID=%s,helpCountLineID=%s" % (mapID, funcLineID, helpCountLineID), playerID) curTime = int(time.time()) maxHelpPlayerCount = IpyGameDataPY.GetFuncCfg("HelpBattleCall", 2) # ×î´óÖúÕ½ÈËÊý checkInValidHours = IpyGameDataPY.GetFuncCfg("HelpBattleCheckIn", 1) # µÇ¼ÇÓÐЧʱ³¤£¬Ð¡Ê± checkInValidSeconds = checkInValidHours * 3600 atmostRobotCount = IpyGameDataPY.GetFuncCfg("HelpBattleCall2", 3) # ÖúÕ½Áбí»úÆ÷ÈËÖÁ¶àÊýÁ¿ allowNoRelation = IpyGameDataPY.GetFuncCfg("HelpBattleCall2", 4) # ÖúÕ½ÁбíÊÇ·ñ³öÏÖ·ÇÉç½»¹ØÏµÍæ¼Ò onlyFree = True checkInPlayerIDList = PyGameData.g_fbHelpBattleCheckInPlayerDict.keys() random.shuffle(checkInPlayerIDList) # ˢд¿Ëæ»ú GameWorld.Log(" µÇ¼ÇÖúÕ½ÈËÊý=%s" % (len(checkInPlayerIDList)), playerID) for checkInPlayerID in checkInPlayerIDList: if len(helpBattlePlayerDict) >= maxHelpPlayerCount: GameWorld.DebugLog(" ³¬¹ý×î´ó¸öÊýÁ˲»´¦Àí, checkInPlayerID=%s" % checkInPlayerID) break helpBattlePlayer = PyGameData.g_fbHelpBattleCheckInPlayerDict[checkInPlayerID] canHelp, needGoldCall = __CheckCanHelpComm(playerID, helpBattlePlayerDict, checkInPlayerID, helpBattlePlayer, limitLV, fightPowerMin, fightPowerMax, checkInValidSeconds, curTime, helpCountKey, dayFreeHelpCount, onlyFree) if not canHelp: continue relation = __GetHelpBattleRelation(curPlayer, helpBattlePlayer) if not allowNoRelation and not relation: continue helpBattlePlayer.todayHelpCountDict[helpCountKey] = helpBattlePlayer.todayHelpCountDict.get(helpCountKey, 0) + 1 helpBattlePlayerDict[checkInPlayerID] = __GetNotifyMapServerHelpPlayerInfoDict(helpBattlePlayer, needGoldCall, helpBattlePlayer.job, relation) nowRobotCount = 0 # ²»×ãµÄ»úÆ÷ÈËNPC²¹×ã openJobList = IpyGameDataPY.GetFuncEvalCfg("OpenJob", 1) # ¿ª·ÅµÄÖ°Òµ lackCount = maxHelpPlayerCount - len(helpBattlePlayerDict) robotID = 0 # »úÆ÷ÈËNPC¶¨ÒåID´Ó1¿ªÊ¼ while lackCount > 0 and robotID < MaxRobotID and nowRobotCount < atmostRobotCount: robotID += 1 if robotID in helpBattlePlayerDict: continue lackCount -= 1 nowRobotCount += 1 randJob = random.choice(openJobList) helpBattlePlayerDict[robotID] = __GetNotifyMapServerHelpPlayerInfoDict(None, False, randJob) GameWorld.Log(" helpBattlePlayerDict=%s" % (helpBattlePlayerDict), playerID) return [helpBattlePlayerDict] def __DoFBHelpBattleCall(callPlayerID, callPlayerName, msgList): ''' ÖúÕ½ÕÙ»½£¬²»¹Ü×îÖÕ¹ý¹ØÓë·ñ£¬±»ÕÙ»½·½¶¼Ö±½ÓËãÖúÕ½³É¹¦£¬ÕâÀï´¦Àí±»ÕÙ»½µÄ£¬Ö÷¶¯·½ÔÚµØÍ¼Ö±½Ó´¦Àí ''' # calledPlayerDict = {} # {±»ÕÙ»½µÄÍæ¼ÒID:¹ØÏµ, ...} mapID, funcLineID, calledPlayerDict = msgList[1:] fbFuncIpyData = IpyGameDataPY.GetIpyGameData("FBFunc", mapID) fbHelpIpyData = IpyGameDataPY.GetIpyGameData("FBHelpBattle", mapID, funcLineID) if not fbFuncIpyData or not fbHelpIpyData or not calledPlayerDict: return helpCountLineID = funcLineID # ÖúÕ½´ÎÊýËùÊôlineID£¬µ±ËùÓвãͨÓÃʱ£¬Ä¬ÈÏΪ0 dayFreeHelpCountInfo = fbHelpIpyData.GetDayFreeHelpCount() if dayFreeHelpCountInfo and len(dayFreeHelpCountInfo) == 2: isAllLineCount = dayFreeHelpCountInfo[1] if isAllLineCount: helpCountLineID = 0 helpCountKey = (mapID, helpCountLineID) GameWorld.DebugLog("ÕÙ»½ÖúÕ½: mapID=%s, funcLineID=%s, helpCountKey=%s, calledPlayerDict=%s" % (mapID, funcLineID, helpCountKey, calledPlayerDict), callPlayerID) for calledPlayerID in calledPlayerDict.keys(): if calledPlayerID not in PyGameData.g_fbHelpBattleCheckInPlayerDict: continue helpBattlePlayer = PyGameData.g_fbHelpBattleCheckInPlayerDict[calledPlayerID] helpBattlePlayer.todayHelpCountDict[helpCountKey] = helpBattlePlayer.todayHelpCountDict.get(helpCountKey, 0) + 1 return def __DoAssistFinish(curPlayer, msgList): ## ЭÖúÍê³É liheItemID, mapID, lineID, assistPlayerIDList = msgList[1:] assistPlayerDict = {} for assistPlayerID in assistPlayerIDList: if assistPlayerID not in PyGameData.g_fbHelpBattleCheckInPlayerDict: continue helpBattlePlayer = PyGameData.g_fbHelpBattleCheckInPlayerDict[assistPlayerID] assistPlayerDict[assistPlayerID] = {"PlayerName":helpBattlePlayer.playerName, "Job":helpBattlePlayer.job, "Face":helpBattlePlayer.face, "FacePic":helpBattlePlayer.facePic, "LV":helpBattlePlayer.playerLV, "RealmLV":helpBattlePlayer.realmLV, "TodayGiftCount":helpBattlePlayer.getThanksGiftCountDict.get(liheItemID, 0)} # ²åÈëÐÂЭÖú¸Ðл PlayerAssist.AddNewAssistThanks(curPlayer, liheItemID, mapID, lineID, assistPlayerDict) return def UpdateGetThanksGiftCountDict(curPlayer, itemID, updateTodayGiftCount): ## ¸üнñÈÕ½ÓÊÕ¸ÐлÀñºÐ´ÎÊý playerID = curPlayer.GetPlayerID() if playerID not in PyGameData.g_fbHelpBattleCheckInPlayerDict: return helpBattlePlayer = PyGameData.g_fbHelpBattleCheckInPlayerDict[playerID] helpBattlePlayer.getThanksGiftCountDict[itemID] = updateTodayGiftCount GameWorld.DebugLog(" ¸üоµÏñЭÖú½ñÈÕ½ÓÊÕ¸ÐлÀñºÐ´ÎÊý: itemID=%s,updateTodayGiftCount=%s" % (itemID, updateTodayGiftCount), playerID) return