فهرست منبع

处理百战生成机器人后,修改配置导致显示异常问题

gitxsm 2 هفته پیش
والد
کامیت
1effc8f9b9

+ 18 - 7
script/module/baiZhanChengShen/BaiZhanChengShenDB.lua

@@ -144,6 +144,17 @@ local function genRobotRaceShow(robotListIdx, race)
     }
     }
 end
 end
 
 
+-- 按当前 robotList 重算已存在机器人的五族 monsterOutID + racePower(保留 name/head 等展示字段)
+local function syncRobotHeroArr(robotListIdx, pinfo)
+    if not robotListIdx or not pinfo then return end
+    normalizePlayer(pinfo)
+    local heroArr = {}
+    for _, race in ipairs(BaiZhanChengShenDefine.BZCS_RACE_ORDER) do
+        heroArr[race] = genRobotRaceShow(robotListIdx, race)
+    end
+    pinfo.showInfo.heroArr = heroArr
+end
+
 local function getRobotScore(robotListIdx)
 local function getRobotScore(robotListIdx)
     local cfg = BzcsConfig.robotList[robotListIdx]
     local cfg = BzcsConfig.robotList[robotListIdx]
     return (cfg and cfg.score) or BaiZhanChengShenDefine.BZCS_INIT_SCORE
     return (cfg and cfg.score) or BaiZhanChengShenDefine.BZCS_INIT_SCORE
@@ -176,6 +187,8 @@ function GenerateRobots(cnt)
                     heroArr = heroArr,
                     heroArr = heroArr,
                 },
                 },
             }
             }
+        else
+            syncRobotHeroArr(i, BzcsData.playerList[uuid])
         end
         end
     end
     end
     rankDirty = true
     rankDirty = true
@@ -243,13 +256,11 @@ function TakePendingRewards(serverId)
     return list
     return list
 end
 end
 
 
--- 跨服启动: 加载数据, 无玩家则生成机器人池, 并向已连接逻辑服同步活动状态
+-- 跨服启动: 加载数据, 同步/补全机器人池, 并向已连接逻辑服同步活动状态
 function initAfterStart()
 function initAfterStart()
     if _G.is_middle ~= true then return end
     if _G.is_middle ~= true then return end
     loadData()
     loadData()
-    if not BzcsData.playerList or not next(BzcsData.playerList) then
-        GenerateRobots()
-    end
+    GenerateRobots()
     rebuildServerList()
     rebuildServerList()
     BzcsLog.logAction("db_init", string.format("playerCnt=%s", Util.getTableCount(BzcsData.playerList or {})))
     BzcsLog.logAction("db_init", string.format("playerCnt=%s", Util.getTableCount(BzcsData.playerList or {})))
     local BaiZhanChengShenCS = require("baiZhanChengShen.BaiZhanChengShenCS")
     local BaiZhanChengShenCS = require("baiZhanChengShen.BaiZhanChengShenCS")
@@ -373,7 +384,7 @@ function BuildRankInfoEntry(pinfo, rank)
         head = si.head or 0,
         head = si.head or 0,
         headFrame = si.headFrame or 0,
         headFrame = si.headFrame or 0,
         serverId = pinfo.serverId or 0,
         serverId = pinfo.serverId or 0,
-        power = BaiZhanChengShenDefine.CalcPlayerPower(si),
+        power = BaiZhanChengShenDefine.CalcPlayerPower(si, pinfo),
         score = pinfo.score or BaiZhanChengShenDefine.BZCS_INIT_SCORE,
         score = pinfo.score or BaiZhanChengShenDefine.BZCS_INIT_SCORE,
         isRobot = pinfo.isRobot,
         isRobot = pinfo.isRobot,
     }
     }
@@ -405,7 +416,7 @@ function BuildOpponentInfoSnapshot(pinfo)
         name = si.name or "",
         name = si.name or "",
         head = si.head or 0,
         head = si.head or 0,
         headFrame = si.headFrame or 0,
         headFrame = si.headFrame or 0,
-        power = BaiZhanChengShenDefine.CalcPlayerPower(si),
+        power = BaiZhanChengShenDefine.CalcPlayerPower(si, pinfo),
         score = pinfo.score or BaiZhanChengShenDefine.BZCS_INIT_SCORE,
         score = pinfo.score or BaiZhanChengShenDefine.BZCS_INIT_SCORE,
     }
     }
 end
 end
@@ -441,7 +452,7 @@ local function makeMatchOpponentEntry(uuid, pinfo)
         serverId = pinfo.serverId or 0,
         serverId = pinfo.serverId or 0,
         name = si.name,
         name = si.name,
         body = getOpponentBody(pinfo),
         body = getOpponentBody(pinfo),
-        power = BaiZhanChengShenDefine.CalcPlayerPower(si),
+        power = BaiZhanChengShenDefine.CalcPlayerPower(si, pinfo),
         score = score,
         score = score,
         isRobot = pinfo.isRobot,
         isRobot = pinfo.isRobot,
     }
     }

+ 25 - 4
script/module/baiZhanChengShen/BaiZhanChengShenDefine.lua

@@ -201,6 +201,20 @@ function GetRobotListCfg(uuid)
     return BzcsConfig.robotList[idx], idx
     return BzcsConfig.robotList[idx], idx
 end
 end
 
 
+-- 机器人总战力: 按 uuid 对应 robotList 五族 monsterOutID 实时求和(与战斗一致)
+function CalcRobotPowerByUuid(uuid)
+    local cfg = GetRobotListCfg(uuid)
+    if not cfg or not cfg.monsterOutIDs then return 0 end
+    local total = 0
+    for _, race in ipairs(BZCS_RACE_ORDER) do
+        local monsterOutID = cfg.monsterOutIDs[race]
+        if monsterOutID then
+            total = total + CalcMonsterOutPower(monsterOutID)
+        end
+    end
+    return total
+end
+
 -- 由 monsterOutID 计算单族队伍战力(与战斗 getMonsterObjList 一致)
 -- 由 monsterOutID 计算单族队伍战力(与战斗 getMonsterObjList 一致)
 function CalcMonsterOutPower(monsterOutID)
 function CalcMonsterOutPower(monsterOutID)
     if not monsterOutID then return 0 end
     if not monsterOutID then return 0 end
@@ -285,12 +299,15 @@ function ExpandBzcsRaceShow(raceShow)
     }
     }
 end
 end
 
 
--- 单族队伍战力: 机器人用 racePower; 真人用 heroArr 内 heroPower 之和
+-- 单族队伍战力: 优先 racePower; 机器人 compact 数据无 racePower 时按 monsterOutID 计算; 真人累加 heroPower
 function CalcRaceTeamPower(raceShow)
 function CalcRaceTeamPower(raceShow)
     if not raceShow then return 0 end
     if not raceShow then return 0 end
-    if raceShow.racePower then
+    if raceShow.racePower ~= nil then
         return raceShow.racePower
         return raceShow.racePower
     end
     end
+    if raceShow.monsterOutID ~= nil then
+        return CalcMonsterOutPower(raceShow.monsterOutID)
+    end
     local sum = 0
     local sum = 0
     for _, h in ipairs(raceShow.heroArr or {}) do
     for _, h in ipairs(raceShow.heroArr or {}) do
         sum = sum + (h.heroPower or 0)
         sum = sum + (h.heroPower or 0)
@@ -298,8 +315,12 @@ function CalcRaceTeamPower(raceShow)
     return sum
     return sum
 end
 end
 
 
--- 玩家总战力 = 五族队伍战力之和
-function CalcPlayerPower(showInfo)
+-- 玩家总战力 = 五族队伍战力之和; 机器人按 uuid 识别(不依赖 isRobot 字段)
+function CalcPlayerPower(showInfo, pinfo)
+    local uuid = pinfo and pinfo.uuid
+    if uuid and GetRobotListIndex(uuid) then
+        return CalcRobotPowerByUuid(uuid)
+    end
     if not showInfo then return 0 end
     if not showInfo then return 0 end
     local total = 0
     local total = 0
     for _, race in ipairs(BZCS_RACE_ORDER) do
     for _, race in ipairs(BZCS_RACE_ORDER) do

+ 14 - 1
script/module/baiZhanChengShen/BaiZhanChengShenNS.lua

@@ -262,6 +262,19 @@ local function checkAllRaceLineupForFight(human)
 end
 end
 
 
 -- 组装并下发 GC_BZCS_MATCH_LIST
 -- 组装并下发 GC_BZCS_MATCH_LIST
+local function resolveMatchOpponentPower(opp)
+    if not opp then return 0 end
+    local power = opp.power or 0
+    if power > 0 then
+        return power
+    end
+    local uuid = opp.uuid
+    if uuid and uuid ~= "" and BaiZhanChengShenDefine.GetRobotListIndex(uuid) then
+        return BaiZhanChengShenDefine.CalcRobotPowerByUuid(uuid)
+    end
+    return power
+end
+
 local function sendMatchListGC(human, myScore, opponentList, myRank)
 local function sendMatchListGC(human, myScore, opponentList, myRank)
     local db = getBzcsDb(human)
     local db = getBzcsDb(human)
     local msgRet = Msg.gc.GC_BZCS_MATCH_LIST
     local msgRet = Msg.gc.GC_BZCS_MATCH_LIST
@@ -280,7 +293,7 @@ local function sendMatchListGC(human, myScore, opponentList, myRank)
         net.rank = opp.rank or 0
         net.rank = opp.rank or 0
         net.name = opp.name
         net.name = opp.name
         net.body = opp.body or 0
         net.body = opp.body or 0
-        net.power = opp.power
+        net.power = resolveMatchOpponentPower(opp)
         net.score = opp.score
         net.score = opp.score
         net.serverId = BaiZhanChengShenDefine.ToClientServerId(opp.serverId, opp.isRobot)
         net.serverId = BaiZhanChengShenDefine.ToClientServerId(opp.serverId, opp.isRobot)
     end
     end