From 11c9a3b5846401523e4dafc17f2a074a712730da Mon Sep 17 00:00:00 2001
From: hxp <ale99527@vip.qq.com>
Date: 星期三, 11 三月 2026 18:27:10 +0800
Subject: [PATCH] 526 【挑战】PVP群英榜-后端(本服群英榜;优化机器人表支持按功能加载不同的机器人;)

---
 ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerViewCache.py |  100 ++++++++++++++++++++++++++-----------------------
 1 files changed, 53 insertions(+), 47 deletions(-)

diff --git a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerViewCache.py b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerViewCache.py
index 216ce3e..2891192 100644
--- a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerViewCache.py
+++ b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerViewCache.py
@@ -32,6 +32,7 @@
 import ShareDefine
 import TurnAttack
 import DBDataMgr
+import CrossMsg
 
 import random
 import time
@@ -267,9 +268,8 @@
     #curCache.SetFamilyEmblemWord(familyBase.GetEmblemWord())
     curCache.SetFightPowerTotal(PlayerControl.GetFightPower(curPlayer))
     curCache.SetServerID(GameWorld.GetPlayerServerID(curPlayer))
-    if isOffline:
-        curCache.SetOffTime(int(time.time()))
-        
+    curCache.SetOffTime(int(time.time()) if isOffline else 0)
+    
     # 装备
     equipDict = {}
     equipPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptEquip)
@@ -369,7 +369,7 @@
     return curCache
 
 def UpdPlayerViewFamilyInfo(playerID, familyID, familyName, emblemID, emblemWord):
-    ## 玩家公会刷新时更新,兼容本服或跨服回传回来更新
+    ## 玩家公会刷新时更新,兼容本服或跨服回传回来更新,跨服自己也更新,本服也更新
     curCache = DBDataMgr.GetPlayerViewCacheMgr().GetPlayerViewCache(playerID)
     if not curCache:
         return
@@ -393,6 +393,7 @@
                     "Face":curPlayer.GetFace(),
                     "FacePic":curPlayer.GetFacePic(),
                     "TitleID":PlayerControl.GetTitleID(curPlayer),
+                    "FamilyID":curPlayer.GetFamilyID(),
                     "ServerID":GameWorld.GetPlayerServerID(curPlayer),
                     "FightPower":PlayerControl.GetFightPower(curPlayer),
                     }
@@ -407,6 +408,7 @@
                         "Face":viewCache.GetFace(),
                         "FacePic":viewCache.GetFacePic(),
                         "TitleID":viewCache.GetTitleID(),
+                        "FamilyID":viewCache.GetFamilyID(),
                         "ServerID":viewCache.GetServerID(),
                         "FightPower":viewCache.GetFightPowerTotal(),
                         }
@@ -425,10 +427,10 @@
     curCache.SetFace(baseInfo.get("Face", curCache.GetFace()))
     curCache.SetFacePic(baseInfo.get("FacePic", curCache.GetFacePic()))
     curCache.SetTitleID(baseInfo.get("TitleID", curCache.GetTitleID()))
+    curCache.SetFamilyID(baseInfo.get("FamilyID", curCache.GetFamilyID()))
     curCache.SetServerID(baseInfo.get("ServerID", curCache.GetServerID()))
     curCache.SetFightPowerTotal(baseInfo.get("FightPower", curCache.GetFightPowerTotal()))
-    if isOffline:
-        curCache.SetOffTime(int(time.time()))
+    curCache.SetOffTime(int(time.time()) if isOffline else 0)
     return curCache
 
 def GetRobotByViewCache(curCache):
@@ -450,36 +452,31 @@
                  }
     return robotDict
 
-def LoadRobot():
-    ## 加载机器人缓存,在服务器启动、重读配置时加载
-    robotFPSortList = []
-    viewCacheMgr = DBDataMgr.GetPlayerViewCacheMgr()
-    ipyDataMgr = IpyGameDataPY.IPY_Data()
-    for index in range(ipyDataMgr.GetRobotCount()):
-        ipyData = ipyDataMgr.GetRobotByIndex(index)
-        robotPlayerID = ipyData.GetID()
-        curCache = viewCacheMgr.GetPlayerViewCache(robotPlayerID)
-        if not curCache:
-            curCache = viewCacheMgr.AddPlayerViewCache(robotPlayerID)
-        if not curCache:
-            continue
-        UpdRobotViewCache(curCache, robotPlayerID, ipyData)
-        robotFPSortList.append([curCache.GetFightPowerTotal(), robotPlayerID])
-    robotFPSortList.sort(reverse=True) # 战力倒序排序
-    IpyGameDataPY.SetConfigEx("robotFPSortList", robotFPSortList)
-    GameWorld.Log("加载机器人战力排序: %s, %s" % (len(robotFPSortList), robotFPSortList))
-    return robotFPSortList
-
-def GetRobotFightPowerSortList():
+def GetRobotFightPowerSortList(tempNum=0):
     ## 机器人战力倒序排序列表
     # @return: 倒序排序列表 [[战力, 机器人ID], ...],外部使用可随机修改,不会打乱原始排序
-    sortList = []
-    robotFPSortList = IpyGameDataPY.GetConfigEx("robotFPSortList")
+    robotFPSortList = IpyGameDataPY.GetConfigEx("robotFPSortList%s" % tempNum)
     if not robotFPSortList:
-        robotFPSortList = LoadRobot()
-    if robotFPSortList:
-        sortList += robotFPSortList
-    return sortList
+        robotFPSortList = []
+        viewCacheMgr = DBDataMgr.GetPlayerViewCacheMgr()
+        ipyDataMgr = IpyGameDataPY.IPY_Data()
+        for index in range(ipyDataMgr.GetRobotCount()):
+            ipyData = ipyDataMgr.GetRobotByIndex(index)
+            if ipyData.GetTempNum() != tempNum:
+                continue
+            robotPlayerID = ipyData.GetID()
+            curCache = viewCacheMgr.GetPlayerViewCache(robotPlayerID)
+            if not curCache:
+                curCache = viewCacheMgr.AddPlayerViewCache(robotPlayerID)
+            if not curCache:
+                continue
+            UpdRobotViewCache(curCache, robotPlayerID, ipyData)
+            robotFPSortList.append([curCache.GetFightPowerTotal(), robotPlayerID])
+        robotFPSortList.sort(reverse=True) # 战力倒序排序
+        IpyGameDataPY.SetConfigEx("robotFPSortList%s" % tempNum, robotFPSortList)
+        GameWorld.Log("加载机器人战力排序: tempNum=%s,%s, %s" % (tempNum, len(robotFPSortList), robotFPSortList))
+        
+    return robotFPSortList
 
 def UpdRobotViewCache(curCache, robotID, robotIpyData=None):
     ## 更新机器人查看缓存
@@ -493,11 +490,11 @@
         return
     
     #curCache.SetAccID(dbPlayer.AccID)
-    
+    realmLV = robotIpyData.GetRealmLV()
     curCache.SetPlayerName(GameWorld.GbkToCode(robotIpyData.GetRobotName()))
     curCache.SetLV(robotInfo.get("LV", 1))
     curCache.SetJob(robotInfo.get("Job", 1))
-    curCache.SetRealmLV(robotInfo.get("RealmLV", 0))
+    curCache.SetRealmLV(realmLV if realmLV else robotInfo.get("RealmLV", 0))
     curCache.SetFace(robotInfo.get("Face", 0))
     curCache.SetFacePic(robotInfo.get("FacePic", 0))
     curCache.SetTitleID(robotInfo.get("TitleID", 0))
@@ -520,30 +517,34 @@
 #{
 #    tagHead        Head;
 #    DWORD        PlayerID;
-#    BYTE        EquipClassLV;    //大于0为查看指定境界阶装备信息,  0为查看默认信息
+#    DWORD        ServerID;        //玩家服务器ID,发0默认本服玩家
 #};
 def OnCMViewPlayerInfo(index, clientPack, tick):
     curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
+    playerID = curPlayer.GetPlayerID()
     
-    findPlayerID = clientPack.PlayerID
-    #equipClassLV = clientPack.EquipClassLV
+    tagPlayerID = clientPack.PlayerID
+    tagServerID = clientPack.ServerID
     
-    clientPack = GetPack_ViewCache(findPlayerID)
-    if clientPack:
-        NetPackCommon.SendFakePack(curPlayer, clientPack)
-        return
-    if GameWorld.GetDBPlayerAccIDByID(findPlayerID):
-        PlayerControl.NotifyCode(curPlayer, "ViewPlayer_OffLine")
+    # 本服或主服是本服
+    if not tagServerID or tagServerID == GameWorld.GetGameWorld().GetServerID() or playerID < ShareDefine.RealPlayerIDStart:
+        NetPackCommon.SendFakePack(curPlayer, GetPack_ViewCache(tagPlayerID))
         return
     
-    # 跨服玩家发送跨服查询,待扩展...
-    
+    # 直接去目标服务器查询
+    CrossMsg.SendToServer(ShareDefine.S2S_ViewTagPlayer, {"tagPlayerID":tagPlayerID}, [tagServerID], ShareDefine.dirType_All, playerID)
+    return
+
+def S2S_ViewTagPlayer(dataMsg, fromServerID, playerID):
+    tagPlayerID = dataMsg["tagPlayerID"]
+    CrossPlayer.SendFakePackByID(playerID, GetPack_ViewCache(tagPlayerID), fromServerID)
     return
 
 def GetPack_ViewCache(playerID):
     ## 获取同步封包 - 玩家查看缓存
     curCache = FindViewCache(playerID)
     if not curCache:
+        GameWorld.ErrLog("查看玩家找不到目标! playerID=%s" % playerID)
         return
     clientPack = ChPyNetSendPack.tagSCQueryPlayerCacheResult()
     clientPack.PlayerID = curCache.GetPlayerID()
@@ -559,10 +560,15 @@
     clientPack.ServerID = curCache.GetServerID()
     clientPack.FightPower = curCache.GetFightPower()
     clientPack.FightPowerEx = curCache.GetFightPowerEx()
-    clientPack.FamilyID = curCache.GetFamilyID()
+    familyID = curCache.GetFamilyID()
+    familyDataServerID = DBDataMgr.GetFamilyMgr().GetCurCrossServerID()
+    if familyDataServerID <= 0:
+        familyDataServerID = GameWorld.GetGameWorld().GetServerID() # 公会未跨服时默认就是玩家所在服
+    clientPack.FamilyID = familyID
     clientPack.FamilyName = curCache.GetFamilyName()
     clientPack.FamilyEmblemID = curCache.GetFamilyEmblemID()
     clientPack.FamilyEmblemWord = curCache.GetFamilyEmblemWord()
+    clientPack.FamilyDataServerID = familyDataServerID
     clientPack.PlusData = curCache.GetPlusData()
     clientPack.PlusDataSize = len(clientPack.PlusData)
     return clientPack

--
Gitblit v1.8.0