From 819ab7e6091bb882e6106a6d713b0ced1848120f Mon Sep 17 00:00:00 2001
From: hxp <ale99527@vip.qq.com>
Date: 星期一, 23 五月 2022 17:00:17 +0800
Subject: [PATCH] 9415 【BT】【后端】古神战场(击杀积分王广播寻路参数优化;战场机器人AI修改为21,优化AI21寻路)

---
 ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/GameWorldLogic/FBProcess/GameLogic_CrossBattlefield.py |   69 +++++++++++-----------
 ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/NPC/NPCAI/AIType_21.py                                 |  106 +++++++++++++++++++++++++++++++++++
 2 files changed, 141 insertions(+), 34 deletions(-)

diff --git a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/GameWorldLogic/FBProcess/GameLogic_CrossBattlefield.py b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/GameWorldLogic/FBProcess/GameLogic_CrossBattlefield.py
index 8d2278b..ec7f049 100644
--- a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/GameWorldLogic/FBProcess/GameLogic_CrossBattlefield.py
+++ b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/GameWorldLogic/FBProcess/GameLogic_CrossBattlefield.py
@@ -985,21 +985,21 @@
     posPoint = GameMap.GetEmptyPlaceInArea(randPosX, randPosY, radius)
     return posPoint.GetPosX(), posPoint.GetPosY()
 
-def GetFBRobotRandomMovePos(curNPC):
-    ## 获取副本中机器人随机移动坐标点
-    
-    randPosList = []
-    
-    crystalNPCIDPosDict = IpyGameDataPY.GetFuncEvalCfg("CrossBattlefieldCrystal", 1, {})
-    for posX, posY in crystalNPCIDPosDict.values():
-        randPosList.append([posX, posY])
-        
-    factionBuffPosList = IpyGameDataPY.GetFuncEvalCfg("CrossBattlefieldFactionBuff", 2)
-    for posList in factionBuffPosList:
-        for posX, posY in posList:
-            randPosList.append([posX, posY])
-            
-    return random.choice(randPosList)
+#def GetFBRobotRandomMovePos(curNPC):
+#    ## 获取副本中机器人随机移动坐标点
+#    
+#    randPosList = []
+#    
+#    crystalNPCIDPosDict = IpyGameDataPY.GetFuncEvalCfg("CrossBattlefieldCrystal", 1, {})
+#    for posX, posY in crystalNPCIDPosDict.values():
+#        randPosList.append([posX, posY])
+#        
+#    factionBuffPosList = IpyGameDataPY.GetFuncEvalCfg("CrossBattlefieldFactionBuff", 2)
+#    for posList in factionBuffPosList:
+#        for posX, posY in posList:
+#            randPosList.append([posX, posY])
+#            
+#    return random.choice(randPosList)
 
 def __DoLogic_FB_Fighting(tick):
     
@@ -1440,10 +1440,11 @@
                 killScoreKingNotifyList = IpyGameDataPY.GetFuncEvalCfg("CrossBattlefieldScoreKing", 4)
                 if index < len(killScoreKingNotifyList):
                     msgMark = killScoreKingNotifyList[index]
+                    lineID = GameWorld.GetGameWorld().GetLineID()
                     defMapID = GameWorld.GetMap().GetMapID()
                     defPosX = defObj.GetPosX()
                     defPosY = defObj.GetPosY()
-                    PlayerControl.FBNotify(msgMark, [atkFaction, atkName, defFaction, defObj.GetPlayerName(), kingScore, defMapID, defPosX, defPosY])
+                    PlayerControl.FBNotify(msgMark, [atkFaction, atkName, defFaction, defObj.GetPlayerName(), kingScore, defMapID, defPosX, defPosY, lineID])
                     
                 # 玩家击败积分王
                 if atkObjType == IPY_GameWorld.gotPlayer and index == 0:
@@ -2188,24 +2189,24 @@
     
     return True
 
-def GetFBRobotCanAtkObjTypeIDList(curNPC):
-    ## 获取副本中机器人可能可攻击的实例类型ID列表
-    ## @return: [[objType, objID], ...]
-    faction = NPCCommon.GetFaction(curNPC)
-    if not faction:
-        return []
-    
-    defFaction = ShareDefine.CampType_Justice if faction == ShareDefine.CampType_Evil else ShareDefine.CampType_Evil
-    objTypeIDList = []
-    defFactionObj = GetBattleFactionObj(defFaction)
-    for playerID in defFactionObj.onlinePlayerIDList:
-        objTypeIDList.append([IPY_GameWorld.gotPlayer, playerID])
-        
-    for robotID in defFactionObj.robotObjIDList:
-        objTypeIDList.append([IPY_GameWorld.gotNPC, robotID])
-        
-    random.shuffle(objTypeIDList) # 打乱顺序
-    return objTypeIDList
+#def GetFBRobotCanAtkObjTypeIDList(curNPC):
+#    ## 获取副本中机器人可能可攻击的实例类型ID列表
+#    ## @return: [[objType, objID], ...]
+#    faction = NPCCommon.GetFaction(curNPC)
+#    if not faction:
+#        return []
+#    
+#    defFaction = ShareDefine.CampType_Justice if faction == ShareDefine.CampType_Evil else ShareDefine.CampType_Evil
+#    objTypeIDList = []
+#    defFactionObj = GetBattleFactionObj(defFaction)
+#    for playerID in defFactionObj.onlinePlayerIDList:
+#        objTypeIDList.append([IPY_GameWorld.gotPlayer, playerID])
+#        
+#    for robotID in defFactionObj.robotObjIDList:
+#        objTypeIDList.append([IPY_GameWorld.gotNPC, robotID])
+#        
+#    random.shuffle(objTypeIDList) # 打乱顺序
+#    return objTypeIDList
 
 
 ## 玩家攻击玩家是否有惩罚
diff --git a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/NPC/NPCAI/AIType_21.py b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/NPC/NPCAI/AIType_21.py
index 4cacc9f..2d04ffc 100644
--- a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/NPC/NPCAI/AIType_21.py
+++ b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/NPC/NPCAI/AIType_21.py
@@ -81,6 +81,11 @@
         return
     mapID = GameWorld.GetMap().GetMapID()
     lineID = FBCommon.GetFBPropertyMark()
+    dataMapID = FBCommon.GetRecordMapID(mapID)
+    fbRandMovePosDict = IpyGameDataPY.GetFuncEvalCfg("AI198Point", 2, {})
+    if str(dataMapID) in fbRandMovePosDict:
+        __RobotMove2(curNPC, fbRandMovePosDict[str(dataMapID)])
+        return
     posKey = "%d%02d" % (mapID, lineID)
     fbMovePosDict = IpyGameDataPY.GetFuncCfg("AI198Point", 1)
     if posKey not in fbMovePosDict:
@@ -108,6 +113,107 @@
     curNPC.Move(tagPosX, tagPosY)
     return
 
+def __RobotMove2(curNPC, randPosList):
+    ''' 根据多条路径随机移动,不同路径间如果存在交叉点,那么可能随机改变路径
+    @param randPosList: [[[路径A点1x,y],[路径A点2x,y],...], [[路径B点1x,y],[路径B点2x,y],...], ...]
+    '''
+    if not randPosList:
+        return
+    
+    #objID = curNPC.GetID()
+    #npcID = curNPC.GetNPCID()
+    RobotMoveIndexInfo = "RobotMoveIndexInfo" # 上次移动目标坐标点索引信息  i * 100 + j
+    RobotMovePosInfo = "RobotMovePosInfo" # 上次移动目标坐标点 posX * 10000 + posY
+    indexInfo =  curNPC.GetDictByKey(RobotMoveIndexInfo)
+    posInfo =  curNPC.GetDictByKey(RobotMovePosInfo)
+    tagI, tagJ = indexInfo / 100, indexInfo % 100
+    tagPosX, tagPosY = posInfo / 10000, posInfo % 10000
+    curPosX, curPosY = curNPC.GetPosX(), curNPC.GetPosY()
+    
+    
+    resetPosPath = True # 重置坐标路径,为True时重新搜索路径
+    # 已经有目标点
+    if tagPosX and tagPosY:
+        # 理论上配置没重读
+        if tagI < len(randPosList) and type(randPosList[tagI]) in [list, tuple] and tagJ < len(randPosList[tagI]) \
+            and randPosList[tagI][tagJ] == [tagPosX, tagPosY]:
+            resetPosPath = False
+            
+    #GameWorld.DebugLog("__RobotMove2: objID=%s,npcID=%s,curPos(%s,%s),tagPos(%s,%s),tagIndex(%s,%s)" 
+    #                   % (objID, npcID, curPosX, curPosY, tagPosX, tagPosY, tagI, tagJ))
+    #GameWorld.DebugLog("    resetPosPath=%s,randPosList=%s" % (resetPosPath, randPosList))
+    
+    # 重置路径,先走向最近的点
+    if resetPosPath:
+        nearestDist = 99999999
+        for i, pathList in enumerate(randPosList):
+            for j, pos in enumerate(pathList):
+                posX, posY = pos
+                tagDist = GameWorld.GetDist(curPosX, curPosY, posX, posY)
+                if tagDist < nearestDist:
+                    nearestDist = tagDist
+                    tagI, tagJ = i, j
+                    tagPosX, tagPosY = posX, posY
+        #GameWorld.DebugLog("    nearestDist=%s" % nearestDist)
+    else:
+        tagDist = GameWorld.GetDist(curPosX, curPosY, tagPosX, tagPosY)
+        #GameWorld.DebugLog("    tagDist=%s" % (tagDist))
+        # 快到达目标点了,预先寻找下个点
+        if tagDist < 2:
+            nearPosIndexList = __getNearPosIndexList(randPosList, tagI, tagJ)
+            #GameWorld.DebugLog("    nearPosIndexList=%s" % nearPosIndexList)
+            if nearPosIndexList:
+                tagI, tagJ = random.choice(nearPosIndexList)
+                tagPosX, tagPosY = randPosList[tagI][tagJ]
+            
+    #GameWorld.DebugLog("    tagPos(%s,%s),tagIndex(%s,%s)" % (tagPosX, tagPosY, tagI, tagJ))
+    curNPC.SetDict(RobotMoveIndexInfo, tagI * 100 + tagJ)
+    curNPC.SetDict(RobotMovePosInfo, tagPosX * 10000 + tagPosY)
+    curNPC.Move(tagPosX, tagPosY)
+    return
+
+def __getNearPosIndexList(randPosList, tagI, tagJ):
+    ## 获取多条路径上相邻的点
+    pathPosList = randPosList[tagI]
+    if not pathPosList or len(pathPosList) <= 1:
+        return
+    
+    tagPosX, tagPosY = randPosList[tagI][tagJ]
+    nearPosIndexList = __getNearIndexByPath(pathPosList, tagI, tagJ)
+    # 检查其他路径交叉点
+    for i, pathList in enumerate(randPosList):
+        if i == tagI:
+            # 本路径不处理
+            continue
+        for j, pos in enumerate(pathList):
+            posX, posY = pos
+            if posX == tagPosX and posY == tagPosY:
+                for ni, nj in __getNearIndexByPath(pathList, i, j):
+                    if [ni, nj] not in nearPosIndexList:
+                        nearPosIndexList.append([ni, nj])
+    return nearPosIndexList
+
+def __getNearIndexByPath(pathPosList, tagI, tagJ):
+    ## 获取某条路径上的相邻点索引信息
+    nearPosIndexList = []
+    # 起始点 或 最终点
+    if tagJ == 0 or tagJ == len(pathPosList) - 1:
+        # 起点=终点
+        if pathPosList[0] == pathPosList[-1]:
+            nearPosIndexList.append([tagI, 1])
+            nearPosIndexList.append([tagI, -2])
+        # 起点
+        elif tagJ == 0:
+            nearPosIndexList.append([tagI, 1])
+        else:
+            nearPosIndexList.append([tagI, -2])
+            
+    # 中间点,取前后两点
+    else:
+        nearPosIndexList.append([tagI, tagJ - 1])
+        nearPosIndexList.append([tagI, tagJ + 1])
+    return nearPosIndexList
+
 #---------------------------------------------------------------------
 ## npc攻击逻辑
 #  @param curNPC 当前npc

--
Gitblit v1.8.0