From 8a132929e7184bc274b742d3e25b93782c65e9ef Mon Sep 17 00:00:00 2001
From: hxp <ale99527@vip.qq.com>
Date: 星期五, 12 十二月 2025 14:32:56 +0800
Subject: [PATCH] 16 卡牌服务端(后台查看玩家、物品)

---
 ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerViewCache.py |   86 +++++++++++++++++++++++++++++++++---------
 1 files changed, 67 insertions(+), 19 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 d351da2..0178843 100644
--- a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerViewCache.py
+++ b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerViewCache.py
@@ -37,8 +37,6 @@
     return
 
 def OnPlayerLogout(curPlayer):
-    if curPlayer.GetLV() < IpyGameDataPY.GetFuncCfg("PlayerViewCache", 1):
-        return
     
     playerID = curPlayer.GetPlayerID()
     curCache = FindViewCache(playerID)
@@ -112,6 +110,17 @@
         
     return False
 
+def FindBattleViewCache(playerID):
+    ## 获取可战斗的玩家缓存
+    # @return: None-无;curCache-有返回该缓存对象
+    curCache = FindViewCache(playerID)
+    if not curCache:
+        return
+    plusDict = curCache.GetPlusDict()
+    if "Lineup" not in plusDict:
+        return
+    return curCache
+
 def FindViewCache(playerID):
     '''查找玩家缓存,如果不存在,则会有额外逻辑,如从redis、db直接找,
             本服玩家理论上一定有查看缓存,因为如果不存在会直接从db读,除非该玩家数据被删除
@@ -146,23 +155,34 @@
             # 逻辑待扩展
             
     # 机器人
-    elif ShareDefine.RobotIDStart <= playerID <= ShareDefine.RobotIDMax:
-        curCache = UpdRobotViewCache(playerID)
+    #elif ShareDefine.RobotIDStart <= playerID <= ShareDefine.RobotIDMax:
+    elif IpyGameDataPY.GetIpyGameDataNotLog("Robot", playerID):
+        GameWorld.DebugLog("加载机器人缓存: %s" % playerID)
+        curCache = viewCacheMgr.AddPlayerViewCache(playerID)
+        curCache = UpdRobotViewCache(curCache, playerID)
         
     # 假玩家,默认添加
     elif ShareDefine.FackPlayerIDStart <= playerID <= ShareDefine.FackPlayerIDMax:
-        serverID = playerID % 100 + 1 # 1 ~ 100 服
-        accID = "fake%s@test@s%s" % (playerID, serverID)
-        fightPower = random.randint(1000000, 100000000) # 先随机,外层有需要的话再自己设置
+        GameWorld.DebugLog("加载假玩家缓存: %s" % playerID)
+        # 随机复制个机器人数据
+        ipyDataMgr = IpyGameDataPY.IPY_Data()
+        robotIpyData = ipyDataMgr.GetRobotByIndex(random.randint(0, ipyDataMgr.GetRobotCount() - 1))
         
         curCache = viewCacheMgr.AddPlayerViewCache(playerID)
-        curCache.SetPlayerName("%s%s" % (GameWorld.GbkToCode("神秘道友"), playerID))
+        curCache = UpdRobotViewCache(curCache, robotIpyData.GetID())
+        
+        # 再覆盖部分数据
+        serverID = playerID % 100 + 1 # 1 ~ 100 服
+        accID = "fake%s@test@s%s" % (playerID, serverID)
+        #fightPower = random.randint(1000000, 100000000) # 先随机,外层有需要的话再自己设置
+        
+        curCache.SetPlayerName("%s%s" % (GameWorld.GbkToCode("主公"), playerID))
         curCache.SetAccID(accID)
-        curCache.SetLV(random.randint(100, 200))
-        curCache.SetJob(random.randint(1, 2))
-        curCache.SetRealmLV(random.randint(5, 15))
-        curCache.SetFightPowerTotal(fightPower)
         curCache.SetServerID(serverID)
+        #curCache.SetLV(random.randint(100, 200))
+        #curCache.SetJob(random.randint(1, 2))
+        #curCache.SetRealmLV(random.randint(5, 15))
+        #curCache.SetFightPowerTotal(fightPower)
         curCache.SetOffTime(int(time.time()) - random.randint(1, 3600 * 24 * 10)) # 随机离线 0~10天
         
     return curCache
@@ -332,9 +352,41 @@
                  }
     return robotDict
 
-def UpdRobotViewCache(robotID):
+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():
+    ## 机器人战力倒序排序列表
+    # @return: 倒序排序列表 [[战力, 机器人ID], ...],外部使用可随机修改,不会打乱原始排序
+    sortList = []
+    robotFPSortList = IpyGameDataPY.GetConfigEx("robotFPSortList")
+    if not robotFPSortList:
+        robotFPSortList = LoadRobot()
+    if robotFPSortList:
+        sortList += robotFPSortList
+    return sortList
+
+def UpdRobotViewCache(curCache, robotID, robotIpyData=None):
     ## 更新机器人查看缓存
-    robotIpyData = IpyGameDataPY.GetIpyGameData("Robot", robotID)
+    if not robotIpyData:
+        robotIpyData = IpyGameDataPY.GetIpyGameData("Robot", robotID)
     if not robotIpyData:
         return
     try:
@@ -342,13 +394,9 @@
     except:
         return
     
-    viewCacheMgr = DBDataMgr.GetPlayerViewCacheMgr()
-    curCache = viewCacheMgr.GetPlayerViewCache(robotID)
-    if not curCache:
-        curCache = viewCacheMgr.AddPlayerViewCache(robotID)
     #curCache.SetAccID(dbPlayer.AccID)
     
-    curCache.SetPlayerName(robotInfo.get("PlayerName", "p%s" % robotID))
+    curCache.SetPlayerName(GameWorld.GbkToCode(robotIpyData.GetRobotName()))
     curCache.SetLV(robotInfo.get("LV", 1))
     curCache.SetJob(robotInfo.get("Job", 1))
     curCache.SetRealmLV(robotInfo.get("RealmLV", 0))

--
Gitblit v1.8.0