From 7517615ae0f931c440e7cd3ba9ad558e9309640e Mon Sep 17 00:00:00 2001
From: hxp <ale99527@vip.qq.com>
Date: 星期一, 10 十二月 2018 11:47:50 +0800
Subject: [PATCH] 5305 【后端】【1.3.100】助战列表刷新规则优化

---
 ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerFBHelpBattle.py   |  184 ++++++++++++++++++++++++++++++---------------
 ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerSocial.py         |    2 
 ServerPython/CoreServerGroup/GameServer/Script/GM/Commands/HelpCheckInInfo.py |   45 +++++++++++
 3 files changed, 169 insertions(+), 62 deletions(-)

diff --git a/ServerPython/CoreServerGroup/GameServer/Script/GM/Commands/HelpCheckInInfo.py b/ServerPython/CoreServerGroup/GameServer/Script/GM/Commands/HelpCheckInInfo.py
index 4a6c378..2dbb3c5 100644
--- a/ServerPython/CoreServerGroup/GameServer/Script/GM/Commands/HelpCheckInInfo.py
+++ b/ServerPython/CoreServerGroup/GameServer/Script/GM/Commands/HelpCheckInInfo.py
@@ -17,6 +17,11 @@
 
 import GameWorld
 import PyGameData
+import PlayerFBHelpBattle
+import ShareDefine
+
+import random
+import time
 
 ## 执行逻辑
 #  @param curPlayer 当前玩家
@@ -31,8 +36,13 @@
     helpBattlePlayer = PyGameData.g_fbHelpBattleCheckInPlayerDict[playerID]
     
     if not gmList or len(gmList) < 2:
+        if len(gmList) == 1:
+            __AddFakeHelpPlayer(curPlayer, gmList[0])
+            return
         GameWorld.DebugAnswer(curPlayer, "-------------------------------")
         GameWorld.DebugAnswer(curPlayer, "查看登记信息: HelpCheckInInfo")
+        GameWorld.DebugAnswer(curPlayer, "添加山寨登记: HelpCheckInInfo 山寨数")
+        GameWorld.DebugAnswer(curPlayer, "清除山寨登记: HelpCheckInInfo 0")
         GameWorld.DebugAnswer(curPlayer, "设置今日助战数: HelpCheckInInfo 地图 线路 次数")
         
         __PrintCheckInInfo(curPlayer, helpBattlePlayer)
@@ -57,4 +67,39 @@
     GameWorld.DebugAnswer(curPlayer, "今天助战数: %s" % (helpBattlePlayer.todayHelpCountDict))
     return
 
+def __AddFakeHelpPlayer(curPlayer, addCount):
+    ## 添加假的助战登记
+    if addCount <= 0:
+        clearFakeIDList = []
+        for playerID in PyGameData.g_fbHelpBattleCheckInPlayerDict.keys():
+            if playerID < 10000:
+                PyGameData.g_fbHelpBattleCheckInPlayerDict.pop(playerID)
+                clearFakeIDList.append(playerID)
+        GameWorld.DebugAnswer(curPlayer, "清除假助战登记 %s" % clearFakeIDList)
+        return
+    
+    addFakeIDList = []
+    curTime = int(time.time())
+    nowCheckInCount = len(PyGameData.g_fbHelpBattleCheckInPlayerDict)
+    fakeIDStart = 1000 + nowCheckInCount + 1
+    for fakeID in xrange(fakeIDStart, fakeIDStart + addCount + 1):
+        if fakeID >= 10000:
+            break
+        helpBattlePlayer = PlayerFBHelpBattle.HelpBattlePlayer(fakeID)
+        PyGameData.g_fbHelpBattleCheckInPlayerDict[fakeID] = helpBattlePlayer
+        playerName = "玩家%d" % fakeID
+        helpBattlePlayer.playerName = playerName.decode(ShareDefine.Def_Game_Character_Encoding).encode(GameWorld.GetCharacterEncoding())
+        helpBattlePlayer.playerLV = curPlayer.GetLV()
+        helpBattlePlayer.job = random.randint(1, 2)
+        helpBattlePlayer.realmLV = random.randint(1, 20)
+        helpBattlePlayer.fightPower = 2000000 + fakeID
+        helpBattlePlayer.familyID = 0
+        helpBattlePlayer.vipLV = random.randint(0, 10)
+        helpBattlePlayer.checkInCount = 100
+        helpBattlePlayer.checkInTime = curTime
+        helpBattlePlayer.todayXianyuanCoin = 0
+        addFakeIDList.append(fakeID)
+        
+    GameWorld.DebugAnswer(curPlayer, "添加假助战登记 %s" % addFakeIDList) 
+    return
 
diff --git a/ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerFBHelpBattle.py b/ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerFBHelpBattle.py
index 8e2ef84..1dd2cd0 100644
--- a/ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerFBHelpBattle.py
+++ b/ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerFBHelpBattle.py
@@ -355,7 +355,12 @@
     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 = 0, 0
+    atleastFreeRelationCount = IpyGameDataPY.GetFuncCfg("HelpBattleCall2", 1) # 至少免费社交人数,无社交则忽略
+    atleastRelationCount = IpyGameDataPY.GetFuncCfg("HelpBattleCall2", 2) # 至少社交人数,无社交则忽略(人数包含免费社交人数)
+    GameWorld.DebugLog("    atleastFreeRelationCount=%s,atleastRelationCount=%s" % (atleastFreeRelationCount, atleastRelationCount))
     
     #已经召唤的保留
     for calledPlayerID, callInfo in calledPlayerIDDict.items():
@@ -366,6 +371,10 @@
             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:
             helpBattlePlayerDict[calledPlayerID] = __GetNotifyMapServerHelpPlayerInfoDict(None, False, job)
@@ -383,47 +392,71 @@
     checkInValidSeconds = checkInValidHours * 3600
     
     checkInPlayerIDList = PyGameData.g_fbHelpBattleCheckInPlayerDict.keys()
-    random.shuffle(checkInPlayerIDList) # 刷新纯随机
+    random.shuffle(checkInPlayerIDList)
     GameWorld.Log("    登记助战人数=%s" % (len(checkInPlayerIDList)), playerID)
+    
+    # 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. 常规添加助战人数        
     for checkInPlayerID in checkInPlayerIDList:
-        if checkInPlayerID == playerID:
-            GameWorld.DebugLog("    自己不处理, checkInPlayerID=%s" % checkInPlayerID)
-            continue
-        if checkInPlayerID in helpBattlePlayerDict:
-            GameWorld.DebugLog("    已经在助战里的不处理, checkInPlayerID=%s" % checkInPlayerID)
-            continue
         if len(helpBattlePlayerDict) >= maxHelpPlayerSelectCount:
             GameWorld.DebugLog("    超过最大个数了不处理, checkInPlayerID=%s" % checkInPlayerID)
             break
         helpBattlePlayer = PyGameData.g_fbHelpBattleCheckInPlayerDict[checkInPlayerID]
-        checkInPlayerLV = helpBattlePlayer.playerLV
-        checkInPlayerFightPower = helpBattlePlayer.fightPower
-        checkInTime = helpBattlePlayer.checkInTime
-        if checkInPlayerLV < limitLV:
-            GameWorld.DebugLog("    等级不足, checkInPlayerID=%s,checkInPlayerLV=%s < limitLV=%s" % (checkInPlayerID, checkInPlayerLV, limitLV))
+        canHelp, needGoldCall = __CheckCanHelpComm(playerID, helpBattlePlayerDict, checkInPlayerID, helpBattlePlayer, limitLV, fightPowerMin, fightPowerMax, 
+                                                   checkInValidSeconds, curTime, helpCountKey, dayFreeHelpCount, onlyFree, goldCallCount, maxGoldHelpPlayerCount)
+        if not canHelp:
             continue
-        if fightPowerMin and checkInPlayerFightPower < fightPowerMin:
-            GameWorld.DebugLog("    战力不足, checkInPlayerID=%s,checkInPlayerFightPower=%s < fightPowerMin=%s" % (checkInPlayerID, checkInPlayerFightPower, fightPowerMin))
-            continue
-        if fightPowerMax and checkInPlayerFightPower > fightPowerMax:
-            GameWorld.DebugLog("    战力超出, checkInPlayerID=%s,checkInPlayerFightPower=%s > fightPowerMax=%s" % (checkInPlayerID, checkInPlayerFightPower, fightPowerMax))
-            continue
-        passTime = curTime - checkInTime
-        if passTime > checkInValidSeconds:
-            GameWorld.DebugLog("    登记超时, checkInPlayerID=%s,checkInTime=%s,passTime=%s > checkInValidSeconds=%s" % (checkInPlayerID, checkInTime, passTime, checkInValidSeconds))
-            continue
-        needGoldCall = False
-        if dayFreeHelpCount:
-            todayHelpCount = helpBattlePlayer.todayHelpCountDict.get(helpCountKey, 0)
-            needGoldCall = todayHelpCount >= dayFreeHelpCount
-            if needGoldCall and goldCallCount >= maxGoldHelpPlayerCount:
-                GameWorld.DebugLog("    超过最大付费召唤人数, checkInPlayerID=%s,goldCallCount=%s > maxGoldHelpPlayerCount=%s" % (checkInPlayerID, goldCallCount, maxGoldHelpPlayerCount))
-                continue
-            goldCallCount += 1
-        relation = __GetHelpBattleRelation(curPlayer, helpBattlePlayer)
-        helpBattlePlayerDict[checkInPlayerID] = __GetNotifyMapServerHelpPlayerInfoDict(helpBattlePlayer, needGoldCall, helpBattlePlayer.job, relation)
         
-    # 不足的机器人NPC补足
+        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开始
@@ -437,6 +470,57 @@
     
     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-盟友
@@ -510,44 +594,20 @@
     relationCoinAddDict = IpyGameDataPY.GetFuncEvalCfg("HelpBattlePoint", 2, {}) # 社交关系加成 {"社交关系":[过关加成, 助战加成], ...} 
     
     isSweep = True
+    onlyFree = True
     checkInPlayerIDList = PyGameData.g_fbHelpBattleCheckInPlayerDict.keys()
     random.shuffle(checkInPlayerIDList) # 刷新纯随机
     GameWorld.Log("    登记助战人数=%s" % (len(checkInPlayerIDList)), playerID)
     for checkInPlayerID in checkInPlayerIDList:
-        if checkInPlayerID == playerID:
-            GameWorld.DebugLog("    自己不处理, checkInPlayerID=%s" % checkInPlayerID)
-            continue
-        if checkInPlayerID in helpBattlePlayerDict:
-            GameWorld.DebugLog("    已经在助战里的不处理, checkInPlayerID=%s" % checkInPlayerID)
-            continue
         if len(helpBattlePlayerDict) >= maxHelpPlayerCount:
             GameWorld.DebugLog("    超过最大个数了不处理, checkInPlayerID=%s" % checkInPlayerID)
             break
         helpBattlePlayer = PyGameData.g_fbHelpBattleCheckInPlayerDict[checkInPlayerID]
-        checkInPlayerLV = helpBattlePlayer.playerLV
-        checkInPlayerFightPower = helpBattlePlayer.fightPower
-        checkInTime = helpBattlePlayer.checkInTime
-        if checkInPlayerLV < limitLV:
-            GameWorld.DebugLog("    等级不足, checkInPlayerID=%s,checkInPlayerLV=%s < limitLV=%s" % (checkInPlayerID, checkInPlayerLV, limitLV))
+        canHelp, needGoldCall = __CheckCanHelpComm(playerID, helpBattlePlayerDict, checkInPlayerID, helpBattlePlayer, limitLV, fightPowerMin, fightPowerMax, 
+                                                   checkInValidSeconds, curTime, helpCountKey, dayFreeHelpCount, onlyFree)
+        if not canHelp:
             continue
-        if fightPowerMin and checkInPlayerFightPower < fightPowerMin:
-            GameWorld.DebugLog("    战力不足, checkInPlayerID=%s,checkInPlayerFightPower=%s < fightPowerMin=%s" % (checkInPlayerID, checkInPlayerFightPower, fightPowerMin))
-            continue
-        if fightPowerMax and checkInPlayerFightPower > fightPowerMax:
-            GameWorld.DebugLog("    战力超出, checkInPlayerID=%s,checkInPlayerFightPower=%s > fightPowerMax=%s" % (checkInPlayerID, checkInPlayerFightPower, fightPowerMax))
-            continue
-        passTime = curTime - checkInTime
-        if passTime > checkInValidSeconds:
-            GameWorld.DebugLog("    登记超时, checkInPlayerID=%s,checkInTime=%s,passTime=%s > checkInValidSeconds=%s" % (checkInPlayerID, checkInTime, passTime, checkInValidSeconds))
-            continue
-        needGoldCall = False
-        todayHelpCount = helpBattlePlayer.todayHelpCountDict.get(helpCountKey, 0)
-        if dayFreeHelpCount:
-            needGoldCall = todayHelpCount >= dayFreeHelpCount
-            if needGoldCall:
-                GameWorld.DebugLog("    不是免费, checkInPlayerID=%s,todayHelpCount=%s > dayFreeHelpCount=%s" % (checkInPlayerID, todayHelpCount, dayFreeHelpCount))
-                continue
-            
+        
         relation = __GetHelpBattleRelation(curPlayer, helpBattlePlayer)
         if not __DoCallHelpPlayer(tagPlayerID, tagPlayerName, helpBattlePlayer, relation, mapID, funcLineID, helpCountKey, isSweep, 
                                   curTime, xianyuanCoinUpper, relationCoinAddDict, baseHelpPoint):
diff --git a/ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerSocial.py b/ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerSocial.py
index 0387fdf..744608c 100644
--- a/ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerSocial.py
+++ b/ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerSocial.py
@@ -99,6 +99,8 @@
     def GetCount(self):
         return len(self.SocialDict)
     
+    def GetSocialIDList(self): return self.SocialDict.keys()
+    
     def Find(self, tagID):
         return self.SocialDict.get(tagID, None)
     

--
Gitblit v1.8.0